Mass migration of Tai peoples from China (Guangxi) to Mainland Southeast Asia and Northern Thailand occurred between the 8th-10th century. The Mainland region was ruled by the Khmer Empire since 800 CE. The Thai established their own kingdoms: the semi-legendary Singhanavati Kingdom (691 BCE–638 CE) evolved into the Ngoenyang Kingdom (638–1292). In 1220, the Khmer controlled Sukhothai was conquered by the Thais and made the capital of the Sukhothai Kingdom. By 1220, the long declining Khmer Empire was mostly overrun by Thais. By the 13th century, the Sukhothai Kingdom (1238–1438) had replaced the Mon kingdoms in Central Thailand. During the reign of King Ramkhamhaeng the Thai script was created in 1283, the arts flourished, Thai institutions were developed, and people called themselves "Thai" as freed people from foreign rule.
In 1351, the Suphannabhum city-state (modern-day Suphan Buri), and Lavo city-state (modern-day Lop Buri) merged into the Ayutthaya Kingdom which was founded near the Chao Phraya River. Duarte Fernandes was the first European to arrive in Ayutthaya in 1511. Siam became the popular international name for Thailand.