During late Warring States period and Qin dynasty, the region was part of Jiuyuan Commandery (九原郡), which was possibly established during King Wuling of Zhao's reign after a successful campaign against the Linhu (林胡) and Loufan (樓煩) peoples. The Xiongnu controlled the region after the fall of Qin dynasty. In 127 BC, general Wei Qing of Han dynasty attacked Xiongnu and conquered Hetao. Wuyuan Commandery was subsequently established on part of the newly gained land. In late Western Han dynasty, the commandery administered 16 counties, including Jiuyuan (九原), Guling (固陵), Wuyuan (五原), Linwo (臨沃), Wenguo (文國), Heyin (河陰), Puze (蒱澤), Nanxing (南興), Wudu (武都), Yiliang (宜梁), Manbai (曼柏), Chengyi (成宜), Guyang (稒陽), Mopang (莫庞), Xi'anyang (西安陽) and Hemu (河目). The population was 231,328, or 39,322 households in 2 AD. During Eastern Han dynasty, the counties Guling, Puze, Nanxing, Guyang, Mopang and Hemu were abolished. The population in 140 AD was 22,957, or 4,667 households. Toward the end Han dynasty, the area's population decreased sharply as residents fled from invading northern nomadic peoples, and the commandery was dissolved.