Nanzhao encompassed many ethnic and linguistic groups. Some historians believe that the majority of the population were of the Bai people, but that the elite spoke a variant of Nuosu, a Tibeto-Burman language closely related to Burmese. By the fourth century they had gained control of the region, but they rebelled against the Sui dynasty in 593 and were destroyed by a retaliatory expedition in 602. The Cuan split into two groups known as the Black and White Mywa. The White Mywa tribes settled on the fertile land around the alpine fault lake Erhai. These tribes were called Mengshe, Mengxi, Langqiong, Tengtan, Shilang, and Yuexi. Each tribe had its own kingdom, known as a zhao. In 704 the Tibetan Empire made these kingdoms into vassals or tributaries. In the year 737 AD, with the support of the Tang dynasty of China, Piluoge of Mengshe united the six zhaos in succession, establishing a new kingdom called Nanzhao. The capital was established in 738 at Taihe,. Located in the heart of the Erhai valley, the site was ideal: it could be easily defended against attack and it was in the midst of rich farmland. In academia, the ethnic composition of the Nanzhao kingdom's population has been debated for a century. Chinese scholars tend to favour the theory that the rulers came from the aforementioned Bai or Yi groups, while some non-Chinese scholars subscribed to the theory that the Thai ethnic group was a major component, that later moved south into modern-day Thailand and Laos.
Expansion
Piluoge died in 748, and was succeeded by his son Geluofeng. When the Chinese prefect of Yunnan attempted to rob Nanzhao envoys in 750, Geluofeng attacked, killing the prefect and seizing nearby Tang territory. In retaliation, the Tang governor of Jiannan, Xianyu Zhongtong, attacked Nanzhao with an army of 80,000 soldiers in 751. He was defeated by Duan Jianwei with heavy losses at Xiaguan. Duan Jianwei's grave is two kilometres west of Xiaguan, and the Tomb of Ten Thousand Soldiers is located in Tianbao Park. In 754, another Tang army of 100,000 soldiers, led by General Li Mi, approached the kingdom from the north, but never made it past Mu'ege. By the end of 754, Geluofeng had established an alliance with the Tibetans against the Tang that would last until 794. In 801 Nanzhao and Tang forces defeated a contingent of Tibetan and Abbasid slave soldiers. Bolstered by these successes, Nanzhao expanded rapidly into Burma, conquering the Pyu city-states in the 820s, finally eliminating them in 832. In 829, they attacked Chengdu, but withdrew the following year. In the 830s, they conquered the neighboring kingdoms of Kunlun to the east and Nuwang to the south. In 846, Nanzhao raided the southern Tang circuit of Annam. Relations with the Tang broke down after the death of Emperor Xuanzong in 859, when the Nanzhao king Shilong treated Tang envoys sent to receive his condolences with contempt, and launched raids on Bozhou and Annam. Shilong attacked Annam again in 863, occupying it for three years. In 869, he laid siege to Chengdu but failed to capture it.
Decline
By 873, Nanzhao had been expelled from Sichuan. They were driven from the Bozhou region, modern Guizhou, in 877 by a local military force organized by the Yang family from Shanxi. They retreated to Yunnan, after which the kingdom slowly declined. In 902, the dynasty came to a bloody end when the chief minister murdered all of the key members of the royal family, including the heir apparent. Three other dynasties followed in quick succession: Da Changhe, Da Tianxing and Da Yining. Finally Duan Siping seized power in 937 and established the Dali Kingdom.
Religion
The area had a strong connection with Tantric Buddhism, which has survived to this day at Jianchuan and neighboring areas. The worship of Guanyin and Mahākāla is very different from other forms of Chinese Buddhism. Nanzhao likely had strong religious connections with the Pagan Kingdom in what is today Myanmar, as well as Tibet and Bengal. The particular form of Buddhism practiced in Nanzhao and the Dali Kingdom was known as Azhali, founded around 821-824 by a monk from India called Li Xian Maishun. More monks from India arrived in 825 and 828 and built a temple in Heqing. The last king of Nanzhao established Buddhism as the official state religion.