Seljuks defeat Qarakhanids
Bukhara, UzbekistanIn 1040, the Seljuk Turks defeated the Ghaznavids at the Battle of Dandanaqan and entered Iran. Conflict with the Karakhanids broke out, but the Karakhanids were able to withstand attacks by the Seljuks initially, even briefly taking control of Seljuk towns in Greater Khorasan. The Karakhanids, however, developed serious conflicts with the religious classes (the ulama), and the ulama of Transoxiana then requested the intervention of the Seljuks. In 1089, during the reign of Ibrahim's grandson Ahmad b. Khidr, the Seljuks entered and took control of Samarkand, together with the domains belonging to the Western Khanate. The Western Karakhanids Khanate became a vassal of the Seljuks for half a century, and the rulers of the Western Khanate were largely whomever the Seljuks chose to place on the throne. Ahmad b. Khidr was returned to power by the Seljuks, but in 1095, the ulama accused Ahmad of heresy and managed to secure his execution. The Karakhanids of Kashgar also declared their submission following a Seljuk campaign into Talas and Zhetysu, but the Eastern Khanate was a Seljuk vassal for only a short time. At the beginning of the 12th century they invaded Transoxiana and briefly occupied the Seljuk town of Termez