Tang campaign against Karakhoja

The Tang campaign against Karakhoja, known as Gaochang in Chinese sources, was a military campaign in 640 CE conducted by Emperor Taizong of the Tang dynasty against the Tarim Basin kingdom of Karakhoja, based in the city of Turfan in Xinjiang. The Western Turks provided their ally Karakhoja with soldiers, but the army retreated when the Tang forces arrived. Karakhoja surrendered and the kingdom was incorporated as a Tang prefecture.

Background
Sporadically controlled by previous Chinese dynasties, Karakhoja was home to a large Chinese population. The kingdom was heavily influenced by Chinese culture and was the closest of the Tarim Basin oasis states to Tang China. Karakhoja had been ruled since 498 by the Qu royal family, who governed the state as the most sinicized of the Tarim Basin kingdoms. During the reign of the Qu, Chinese was the official written language of Karakhoja, students were taught with the Chinese classics, and the government bureaucracy was based on the political structure of imperial China.

Campaign
The Tu-lu Qaghan, who had risen to power in 638, offered Karakhoja the military protection of the Western Turkic Khaganate. With the support of the Western Turks, Karakhoja halted the Silk Road trade route that connected Tang China with Central Asia. In response, Emperor Taizong dispatched a military campaign led by general Hou Junji. The army reached Karakhoja in 640 and defeated the oasis state. The Western Turk forces sent to defend Karakhoja fled as the Tang soldiers approached. The son of Qu Wentai, the king of Karakhoja, surrendered and the former kingdom was annexed.

Aftermath
Following the annexation of Karakhoja, the oasis state was placed under direct Tang administration and structured as a prefecture. Karakhoja was overseen as part of the Anxi Protectorate, or Protectorate General to Pacify the West, established to govern the Western Regions of Xinjiang. Soon after the conquest, a population census was conducted to implement the equal-field system mandatory for Chinese prefectures. In 640, the year of Karakhoja's annexation, it was reported that there were 8,000 households and 37,700 inhabitants living in Turfan.

The fall of Karakhoja raised the suspicions of the nearby kingdom of Karasahr. Threatened by Chinese troops stationed in the region, Karasahr sided with the Western Turks. The Tang responded by invading and annexing Karasahr in 644.