In 1253, Kublai Khan and his Mongol horsemen attacked and defeated NanChao. With Shan aid, they then defeated the Burmese (1277). The power of the Mongols and their Yuan Dynasty Chinese Empire were a clear threat to all peoples of the entire region.
In 1262, young King Mengrai came from Hiram Ngoen Yang, the capital of Yonok Naknakorn, to found Chiang Rai at Doi Jomtong, by the village of Pantu Nakorn, on the south bank of the Kok River. This was only the first capital of his new Lanna Kingdom, though. The village at that location was Muang Chiang Lao until about 1050 AD, when it became Chai Narai. Chai Narai was destroyed, perhaps by the Mahachai earthquake and flood. That flood, however, had produced just the barrier Lanna people needed for protection against invasion from the north. A story taught in Thai public schools tells of Mengrai's war elephant wandering off and stopping at Doi Jom Tong, and how when Mengrai tracked it to there, he decided it a good place to build a city. Perhaps the war elephant is symbolic of military necessity.
Mengrai's mother was a daughter of the Tai Leu ruler of Chiang Rung (Jinghong, just north of the present border of Burma and Laos); an alliance between Yonok and Chiang Rung can be assumed. Mengrai was born in 1238, and ascended to his throne in 1259, after his parents' deaths (deaths interestingly timely and convenient to any potential for success in his life or rule). He was soon calling on the leaders of smaller T'ai city-states in the Kok River basin to pay homage to his kingdom of Hiram Ngoen Yang. Extending his territory past the Ping River, he first called the area Khwan Ping, then briefly Muang Chiang Rai ('muang' meaning either city, state or country).
At this time, there seems to have been a trading gap - Mon influence came up to Haripunjaya (Lamphun), and Chinese influence came into Yonok and some Shan states, where it met Indian influence. The Mon were in the Ping, Wang and other river valleys of present western Thailand/eastern Myanmar since the 8th century. Sukhotai had various dealings with the Celestial Empire, but there's little evidence of Sino-Mon trade.
Mengrai mediated peace between Ramkamhaeng and Ngam Muang, and by maintaining that peace, while instituting Theravada Buddhism as the state religion, consolidated political power in central and north Thailand (around 1287). The three kings strengthened the "Culture of the Dhamma Letters," and protected each other's backs. Thus much more secure, Mengrai kept the Mongols at bay.
When Mengrai came to power, important towns were Doi Tung, Chiang Kwang, Yong, and Chai Prakan (Fang). Quickly expanding his power, Mengrai moved his court frequently, in 1272 building a new one at Fang. Within little over a decade he also had strong fortresses at Chiang Rai (Jamraya), Chiang Khong, Lamphun and WiangKumKam. Able to move his forces between these fortresses, and even abandon one or more if overwhelmingly attacked, he was able to harass invaders by disrupting supply lines and engaging in hit-and-run attacks from the rear. Mongols did invade, but were soon effectively dissuaded. Lanna soldiers later raided far north, well into the territory Mongols ruled.
Another well-planned strategy enabled Mengrai to seize the wealthy and influential Haripunchai (Haripunjaya, later Lamphun). The northernmost of Mon-Dvaravati cities, founded in 675 AD by PhanangJamatevi of Lopburi, the Khmers took it in the 10th century. When the Mon-Dverati Empire lost power to the Khmers in the early 11th century, Haripunchai grew into extensive political independence and wealth, with lucrative trading connections extending far to the south.
According to M.L. Manich Jumsai's "Popular History of Thailand" (Chalermnit, Bangkok, 2000), Mengrai used two Lawa men to infiltrate a twon called Khoen. The two told their fellow Lawa that "they were expelled by Mangrai," and prepared the way for Mengrai "to come and take the town." In 1262 he rebuilt it as Chiengtung (Kengtung in Burmese), Jumsai says, but this is neither mentioned in the ChiangMai Chronicle not acknowledged by Shan historians. A similar strategy, though, worked against Phya Yi-ba of Haripunchai: Mengrai found a man who could act as his spy by re-entering government service there. It took this agent, a Lawa called Ai Fa, seven years, but he eventually undermined the local ruler's authority by instituting expensive and difficult construction projects, and paved the way for Mengrai's successful take-over (1281). Mengrai ruled from there 3 years, then moved to nearby Chawae, and shortly thereafter a little further on to WiangKumKam.
Mengrai founded Nopburi SiNakawnPing Chiengmai (Chiang Mai) in 1296, where Wiang Nophaburi (an existing Lawa city) was; nearby were Lawa cities Muang Ruang, Pinkarat, Wiang Chet Rin, Chesanthaburi, and Wiang Suan Dok, fore-runners to the New City. Much that now seems superstition was given in explanation for the decision, but some main rational reasons were:
1. Its location between the Kok and Ping River basins made a good strategic position, defensible and central enough for supervision of a large kingdom
2. Its location on the north-south trading route of the Ping River was valuable for trade and commerce
3. The large fertile plain of the Ping River was suitable for a large agricultural community.
4. The area slopes gently down from west to east, with a stream flowing from Doi Suthep, which, with a lake sitting to the northeast, ensured good water supply
5. The Mongols had unified SipsongPanna and northern Laos as Cheli, and had been set to invade Lanna since 1270. Close proximity to Cheli was not safe; the other capitals had been further north and Mangrai needed more distance.
At Pinkarat and Doi Suthep, the mountain above, besides Tai related peoples (Tai Yong, Tai Yuan, Tai Leu, Tai Khoen, and Tai Yai), there were already Lawa, Lua, Mon, and other peoples. The Wa, wild indigenous headhunters related to the civilized Lawa, Mengrai drove north past Bankham (near Bhamo). Mengrai successfully promoted markets, craftsmanship, city building, religion and his code of law (Mangraisat). It seems unlikely that much over a million people lived in Lanna at this time, but there were certainly many hundreds of thousands. With assimilation of Mon people from Haripunchai/Lamphun, the social organization and technical level of Mengrai's kingdom was able to advance. Although the primitive animism of local tribes remained, Mon trappings raised Lanna culture to a respectable, formidable height.