The Battle of Andkhud, also spelt as Battle of Andkhui was fought in 1204 on the bank of river Oxus near Andkhoy in present-day Afghanistan. It was fought between the Ghurid forces of Muhammad of Ghor against the Qara Khitai forces (as aid of Khwarazmian Empire) led by Tayangu of Taraz. The battle ended in a complete rout of the Ghurids, although Muhammad of Ghor managed to escape the debacle after the intervention by Uthman of Qarakhanid.
The Ghurids, soon after the death of Tekish of Khwarezm, invaded and annexed most of the Khorasan amidst the civil war among the successors of Tekish for the throne. However, the Ghurids conquests were recaptured by Alauddin Shah who made diplomatic overtures to make peace with the Ghurids. Although, the Ghurids turned down his overtures. Ghiyath al-Din Muhammad at this point, died in Herat (1203) and was succeeded by his brother Muhammad of Ghor. Alauddin soon displaced the Ghurid governor from Herat and relieved the city which lead to a full-scale invasion from Muhammad of Ghor who besieged Alauddin's capital of Gurganz. However, the Ghurids failed to press upon the siege and were forced to retreat when a large contingent of Qara Khitai and Qarakhanid forces come in aid of the Khwarazmians.
The Ghurids were chased in their retreat and in a decisive battle fought near the river of Oxus, in Andkhud, Muhammad's forces were completely routed by Qara Khitais who further chased him in his retreat as well. Muhammad was allowed to retreat safely to Ghazna after paying heavy ransom to Tayangu.
The Catastrophe of Andhkhud lead to the loss of most of the Khurasan for the Ghurids and a number of their slave generals rebelled in the core Ghurid domain as well. Muhammad of Ghor, however successfully dealt with these rebellions and made preparations to avenge his defeat but was assassinated at Damyak on 15 March 1206. His successor was forced to acknowledge the suzerainty of Khwarazmians who overthrew the Ghurids by 1215 but were themselves uprooted by Genghis khan in 1221.
Background
By close of the twelfth century, the Ghurid Empire under the dyarchy of Ghiyath al-Din Muhammad and his younger sibling Muhammad of Ghor reached its greatest territorial extent. After expelling the Ghaznawids from their last bastion in 1186, the Ghurids achieved a landscape victory in 1192, against the forces of Chahamana king Prithviraja III in Second Battle of Tarain which opened the whole of Ganga valley which Muhammad and his slave generals pressed upon in subsequent years and reached as far as the Ganges Delta in Bengal. After their conquests in the Indian subcontinent, the Ghurids embarked upon the struggle with Khwarazm Empire for the supremacy of Khorasan.
Meanwhile, Tekish died in 1200 and was succeeded by his son Alauddin Shah. Taking advantage of the civil war between Alauddin and his nephew Hindu Khan for the throne, the Ghurids successfully captured Nishapur, Merv, Tus and reached right up to Gorgan and Bisṭām. Further, in Merv, the Ghurids stationed Alauddin's rival Hindu Khan on the throne. Thus, the Ghurids for a short time captured most of the Khorasan for the first time. However, Alauddin soon ascended to the throne in August 1200 and recaptured his territories from the Ghurids after a series of incursion which began from September 1201 and recaptured Nishapur and other Ghurid conquests including Herat. Despite this success, Alauddin tried to make cordial relations with the Ghurids (possibly to get rid from Qara Khitai supremacy) and wrote a letter to them to treat him as his son and offered to marry his mother Turkan Khatun to Muhammad of Ghor. However, the overtures by Alauddin were turned down by the Ghurids and they continue to carry raids in Khorasan.
Around the same time, Ghiyath al-Din died in 1203 due to illness in Herat and Muhammad succeeded him as the sole ruler of Ghurid dynasty. Taking advantage of Muhammad absence from Herat, amidst death of his brother, Alauddin defeated the Ghurid garrison in Herat and recaptured the city. However, Muhammad drove back him from Merv and decisively defeated him east of his capital in Gurganz. Muhammad in order to give a decisive blow to the Khwarezmian, besieged their capital Gurganz, possibly to completely annex their empire. Alauddin retreated, and requested aid from the Qara Khitai rulers who were themselves in hostile relations with the Ghurids after their invasion of Balkh. Thus, Qara Khitai's sent a large contingent of 40,000 soldiers under the command of Tayangu of Talas along with Qarakhanid ruler Uthman ibn Ibrahim of Samarkand and his cousin Taj al-Din Bilge Khan.