Tang campaigns against Karasahr

The Tang campaigns against Karasahr, known as Yanqi in Chinese sources, were two military campaigns sent by the Tang Dynasty emperor Taizong against the Tarim Basin kingdom of Karasahr in Xinjiang, a vassal of the Western Turkic Khaganate. The first campaign in 644 was led by the Tang commander Guoxiao Ke, protectorate-general of the Anxi Protectorate in western China, who defeated the oasis state and a Western Turk army at the conquest of Karasahr and installed a Tang loyalist as ruler. The second campaign in 648 was led by the Tang general Ashina She'er, who re-established Chinese control over the kingdom after the Chinese puppet ruler was overthrown.

Background
Karasahr, a kingdom in the Tarim Basin, became a tributary state of Tang China in 632. In 632, the nearby oasis states Kashgar and Khotan surrendered to Chinese suzerainty, as did the kingdom of Yarkand in 635. Karasahr was influenced by Persian culture, Buddhism, and the Greco-Buddhist culture of Afghanistan.

The rulers of Karasahr grew uneasy as the Chinese expanded into Central Asia. After the conquest of the city of Turfan, center of the kingdom of Gaochang, the Chinese army stationed nearby was seen as a direct threat.

Campaign
Karasahr ended its tributary relationship with the Tang Dynasty and formed an alliance with the Western Turkic Khaganate. The state of Kucha, although technically a Tang suzerain, aided Karasahr's rebellion in 644. Fearing Tang military ambitions, Kucha also ended its status as a Chinese tributary state. The Tang emperor responded by sending an army led by commander Guoxiao Ke, protectorate-general of the Anxi Protectorate, against the kingdom. Guo planned a surprise attack, marching towards the city from the Yulduz, and attacked the kingdom at dawn. The oasis state fell in 644 and the king was captured. The Western Turks sent troops to assist Karasahr, but they were defeated by the Tang forces. A puppet king loyal to the Tang Dynasty, Long Lipozhun, a brother of the former king, was installed as ruler. Karasahr was re-established as a vassal and the region was brought under Tang control.

Usurpation and defeat
The Tang loyalist king was ousted by his cousin in a revolt. Karasahr also received support from the Western Turks. The Tang general Ashina She'er, a member of the Turkic Ashina royal family, was sent to Karasahr in 648 to remove the usurper and bring the region back under Tang control. Tang forces defeated Karasahr and the usurper was executed. A new Tang loyalist was installed as ruler of Karasahr.

Aftermath
A Tang military garrison was installed in the kingdom as one of the Four Garrisons of Anxi, created to secure Tang hegemony of the Tarim Basin in southern Xinjiang. The conquest of Karasahr, along with the conquest of Kucha, ended the influence of Indo-European culture in Central Asia. The Tang campaign against the states of the Western Regions brought the majority of the Tarim Basin under Chinese control.

Following the fall of Karasahr, Ashina She'er led his forces in a campaign against the state of Kucha.