The Western Karakhanid State

Mahmud II, for his part, ruled in Khorasan for a while. Indeed, after the death of Sultan Sanjar (1157), the Oghuz offered him the sovereignty. Mahmud first sent his son Muhammad, but after a while he himself became ruler of the Oghuz. Mu'ayyad al-Dawla Ay-Aba, the governor of Nishapur and one of Sanjar's commanders, also desired to seize Khorasan. In the struggle he undertook for this purpose, he captured Mahmud and his son Muhammad and had them blinded (August 1162). The following year father and son died in prison. With their death the Western branch of the Karakhanids also came to an end.

After this, power passed to the family of Ali Tegin, and Ali b. Hasan succeeded Ibrahim III. Ali fought successfully against the Karluks and killed their chief, Yabgu Khan. In 1158 he confronted near Bukhara the allies on whose side, with the Karluks, stood the Khwarazmshah Il-Arslan (1156-1172), but the two sides came to terms without a battle. Later Ali was succeeded by his brother Abu'l-Muzaffar Mas'ud II (1161). Mas'ud II put an end to the disorder in the country and fought against the Karluks and the Oghuz. After his death in 1178 we see Ibrahim IV b. al-Husayn at the head of the Western Karakhanids; he was succeeded by his son Osman I (1204). Osman appears to have been a good and prudent ruler. He was at first subject to the Kara-Khitai; nevertheless he prevented the Muslim Ghurids from being destroyed by them and acted as a mediator for peace. When the Kara-Khitai ruler, the Gur Khan, refused to give him his daughter, Osman submitted to the Khwarazmshah Muhammad by having the khutba read and coins struck in his name.

Later the Kara-Khitai defeated the Khwarazmshah (1207). But Osman was pardoned and even married the Gur Khan's daughter (1210). Osman's subjection to the Kara-Khitai lasted only a very short time, and he came to terms with the Khwarazmshah Muhammad. This time he married his daughter and, according to custom, stayed in Khwarazm for a year. When Osman returned to Samarkand, he broke away from the Khwarazmshahs and drew closer to the Kara-Khitai. The reason for this was that during his absence the Khwarazmians had treated the people of Samarkand badly.

When he killed the Khwarazmians, Muhammad took action; after taking Samarkand he captured Osman. At the instigation of his insulted Khwarazmian wife, Osman was put to death (1212). With his killing the Western Karakhanid State came to an end.