The Karakhanids and Kara-Khitans
According to the 10th century text, Hudud al-'alam, "the chiefs of Kashghar in the days of old were from the Qarluq, or from the Yaghma." The Karluks, Yaghmas and other tribes such as the Chigils formed the Karakhanids. The Karakhanid Sultan Satuq Bughra Khan converted to Islam in the 10th century and captured Kashgar. During the late 10th century, the Muslim Karakhanids began a struggle against the Buddhist Kingdom of Khotan, and the Karakhanids of Kashgar under Yusuf Kadr Khan later conquered Khotan in 1006.
The Karakhanid Khanate was defeated in the 12th century by the Kara-Khitans, however Karakhanid rule continued in Kashgar under the suzerainty of the Kara-Khitans The Kara-Khitans rulers followed a policy of religious tolerance, Islamic religious life continued uninterrupted and Kashgar was also a Nestorian metropolitan see The last Karakhanid of Kashgar was killed in a revolt in 1211 by the city's notables. Kuchlug, a usurper of the throne of the Kara-Khitans, then attacked Kashgar which finally surrendered in 1214.