The capital of the city is the oldest city in northern Thailand. It was founded in 663 AD and was originally called "Lipchai City". Queen Chama Thevi of the Halipunchai Dynasty established her capital here in the 9th century.
The Mongol dynasty established what is now Thailand, and the Halipunchai dynasty was their last power in the region.
It was once ruled by Burma, and was later recaptured by King Zheng and became part of Chiang Mai Prefecture. During the Bangkok Dynasty, the city gradually became stronger and was upgraded to a prefectural government in 1954.