King Phaya Mengrai (also spelt Mangrai) is credited for founding the kingdom of Lanna in the 13th century from his seat at Chiang Saen, but his first attempt at building a new capital on the banks of Mae Ping at Wiang Kum Kam lasted only a few years: the city was eventually abandoned due to flooding.
In 1296 King Mengrai relocated his capital to a more picturesque spot between the river and Doi Suthep mountain and named the auspicious city Nopburi Si Nakhon Ping Chiang Mai (shortened to Chiang Mai, meaning 'New Walled City'). In the 14th and 15th centuries, the Lanna kingdom expanded as far south as Kamphaeng Phet and as far north as Luang Prabang in Laos, but it fell to Burmese invaders in 1556, starting an occupation that lasted 200 years.
After the fall of Ayuthaya in 1767 to the Burmese, the defeated Thai army regrouped under Phraya Taksin in present-day Bangkok and began a campaign to push out the occupying Burmese forces. Chao Kavila (also spelt Kawila), a chieftain from nearby Lampang principality, helped 'liberate' northern Thailand from Burmese control, and was appointed king of the northern states, placing Chiang Mai under the authority of the kingdom of Siam.
Under Kavila, Chiang Mai became an important trading centre, aided by its abundant supplies of teak, and monumental brick walls were built around the inner city. Many of the later Burmese-style temples were built by wealthy teak merchants who emigrated from Burma during this period. In their wake came missionaries and British teak concessionaires who built colonial-style villas around the old city.
The demise of the semi-autonomous Lanna state was only a matter of time. Bangkok designated Chiang Mai as an administrative unit in 1892 in the face of expanding colonial rule in neighbouring Burma and Laos, and the Lanna princess Dara Rasmi was sent to Bangkok to become one of the official consorts of King Rama V, cementing the ties between the two royal families.
The completion of the northern railway to Chiang Mai in 1922 finally linked the north with central Thailand and in 1933 Chiang Mai officially became a province of Siam. Even so, Chiang Mai remained relatively undeveloped until 2001, when prime minister and Chiang Mai native Thaksin Shinawatra sought to modernise the city by expanding the airport and building superhighways.
A high-speed rail link to Bangkok that will reduce travel time to 3½ hours is in planning stages but the date of construction has still not been set.