The Qarakhanids were a Turkish confederation of Qarluqs, ruled by a Qaghan (Khaqan). In the 10th Century the Qarluq became Sunni Muslims and the Qarakhanids were divided into the western half in Transoxania based at Samarkand and Bukhra (Sughd or ancient Sogdiana), and the eastern half based in Balasaghun, Kashgar and Khotan.
- By 1001 AD the Qarakhanids and Ghaznavids had defeated the Samanids. Samanid territory was divided along the Oxus river with Khurasan falling to the Ghaznavids and the Transoxanian provinces to the Qarakhanids. As the dominant power in Transoxania, many Turks (including some early Seljuqs) sought service in Qarakhanid armies.
- An invasion of Ghaznavid-Khurasan occurred in 1006-8.
- Shams al Mulk Nasr b. Ibrahim (1068-1080) invaded Seljuq Tukhrasitan, defeating Ayaz (brother of Malik Shah). Malik Shah then defeated Shams al-Mulk in 1073-4. Shams al-Mulk then unsuccessfully attacked the eastern Qarakhanids, losing both Farghana and Ilaq.
- Shams al-Mulk was succeeded by Khidr-Khan (1080-1) and then Ahmad Khan (1081-9), nephew of Malik Shah's wife Terken Khatun. This did not stop Malik-Shah, who in 1089 captured Samarkand (and Ahmad Khan), pushing further east to receive the submission of Harun b. Sulaiman b. Qadr-Khan Yusuf- the Khan of Kashghar.
- This led to a revolt of the people of Samarkand and the Chigil or Qarluq tribesmen. Ya'qub-Tegin, the brother of the Kashgar Khan, intervened, and Malik-Shah campaigned again in Samarkand and Uzkand, aided by Toghril b. Inal who attacked Kashgar, driving the Khan out. The Seljuqs suppressed the revolt, and encouraged the Khan of Kashgar and Ya'qub-Tegin to recover Kashgar, restoring Ahmad-Khan to power in Samarkand. Ahmad-Khan was later overthrown and killed (1095).
- The Qara-Khitai invasions of the 1130s put the Qarakhanids eventually destroyed the confederation. The eastern Qarakhanids at Kashgar, under Arslan-Khan Ahmad, were defeated in 1133.
- In 1137 the Samarkand branch under Mahmud Khan was defeated.
- The Qarakhanids became embroiled in the Khwarizmian wars with the Qara-Khitai in the last part of the 12th Century. Uthman-Khan (1203-1212) was attacked by the Khwarizmians in retaliation for switching his support back to the Qara-Khitai in 1212. The city of Samarkand was sacked and Uthman-Khan (and his family) were ruthlessly executed, thus ending the western branch of the Qarakhanids.