A large number of ethnicities have inhabited Mongolia since prehistoric times. Most of these people were nomads who, from time to time, formed great confederations that rose to prominence. The first of these, the Xiongnu, were brought together to form a confederation by Modu Shanyu in 209 BCE. They defeated the Donghu, who had previously been the dominant power in eastern Mongolia.
The Xiongnu became the greatest threat to China for the following three centuries; the Great Wall of China was built partly as defence against the Xiongnu. Marshal Meng Tian of the Qin Empire dispersed more than 300,000 soldiers along the Great Wall to prevent an expected invasion from the North. It is believed that after their decisive defeat by the Chinese in 428431, some of the Xiongnu migrated West to become the Huns. After the Xiongnu migrated west, Rouran, a close relative of the Mongols, came to power before being defeated by the Gokturks, who then dominated Mongolia for centuries.