Satuk Bughra Khan

But Nasr wanted to take possession of the entire inheritance of the Samanids and to seize Khorasan. Indeed, the forces he sent into Khorasan in two columns, taking advantage of Sultan Mahmud of Ghazni's being occupied in India, were defeated by Mahmud and by his own brother Nasr. In this situation Nasr was compelled to ask for help from the co-khagan Yusuf b. Harun (Kadır Khan). In this battle on the plain of Balkh, Sultan Mahmud once again routed the united Karakhanid forces (5 January 1008).

This failure led to family quarrels among the Karakhanids. Nasr b. Ali wanted to declare his independence. The Great Khagan Ahmad b. Ali, however, allied himself with Sultan Mahmud against him. In the end the two rivals turned to Mahmud's mediation; Nasr b. Ali died in 1012-13 and was succeeded by the third brother, Mansur.

While Ahmad b. Ali was going through a serious illness, his brother Mansur probably proclaimed himself great khagan. Their brother Muhammad had also recognized Mansur's sovereignty. Ahmad took action against these two brothers. On his side were Yusuf (Kadır Khan) and Ali Tegin. Ali Tegin must have fallen captive to Mansur at this time. The Karakhanids at first acted as mediators between the Ma'munids, who ruled Khwarazm, and the Ghaznavids, but later they were compelled to accept Mahmud's seizure of Khwarazm (1017).

Meanwhile, the great khagan Ahmad rose from his sickbed and, after defeating more than a hundred thousand tents of non-Muslim nomadic Turks who had advanced to within eight days' distance of Balasagun, pursued them for three months as far as Turfan. He died shortly after returning from this campaign (1017-18).

After the death of Ahmad b. Ali there were two candidates who wished to succeed him. One of them, Yusuf Kadır Khan, asked for help from Sultan Mahmud of Ghazni, but did not find what he had hoped for. In the end he came to terms with his rival Abu'l-Muzaffar Mansur b. Ali. These two Karakhanid rulers undertook a joint campaign into Khorasan, but they were defeated by Sultan Mahmud near Balkh (1019/1020). Yusuf was compelled to make peace with Sultan Mahmud once again.