In the late 13th century, King Mengrai united several Tai tribes that had migrated from southern China and built the first capital of the Lanna kingdom in Chiang Rai. Mengrai, whose rule was characterized by strategic alliances, was threatened by Mongol emperor Kublai Khan and his incursion into Myanmar (Burma). He quickly forged ties with the powerful kingdom of Sukhothai in the south. The Lanna king vanquished the vestiges of the Mon Empire in Lamphun and, in 1296, moved his new capital south to what is now Chiang Mai. There is a monument to King Mengrai, around the corner from Chiang Mai's Wat Phan Tao, where he is said to have been struck by lightning and killed in 1317.
For the next century, Chiang Mai prospered and the Lanna kingdom grew, absorbing most of what now comprises the Northern provinces. In cahoots, Chiang Mai and Sukhothai were able to resist significant attacks from Khmer and Mon neighbors. After the Lanna dynasty absorbed Sukhothai, forces from Ayutthaya tried repeatedly to take Chiang Mai, but the city refused to yield. Instead, Chiang Mai grew in strength and prospered until the late 16th century, when it eventually fell to the Burmese in 1557.
After 2 centuries of relentless warfare, the Burmese captured Chiang Mai in 1558, and for the next 2 centuries the Lanna kingdom was a Burmese vassal -- Burmese culture is still in evidence today, especially with regard to clothing and cuisine. After Lampang's Lord or "Chao" Kavila recaptured Chiang Mai from the Burmese in 1775, the city was so weakened that Kavila moved its surviving citizens to nearby Lampang. For 2 decades, Chiang Mai was akin to a ghost town. Though the city was still nominally under the control of local princes, their power continued to decline, and in 1939 Chiang Mai was formally incorporated into the modern Thai nation.