structural:scholar_edition
Later

Tekish died in 1200, which led to a brief period of struggle for the succession between Alauddin Shah of Khwarezm and his nephew Hindu Khan. The Ghurid siblings seized the opportunity and amidst the turmoil in the Khwarezmian house for succession, Muhammad and Ghiyath al-Din invaded and captured the oasis cities of Nishapur, Merv and Tus and reached as far as Gorgan. The Ghurids, thus, for a short span established their sway over most of the Khurasan for first time in their history. However, their success turned to be a short-term affair as Alauddin succeeded the throne in August 1200 and soon after recaptured his lost territories by 1201. Despite the success against the Ghurids, Alauddin sent an envoy for diplomacy to Muhammad, probably in order to focus solely on overcoming from the suzerainty of Qara Khitais by sougthing peace with the Ghurids. However, the attempt turned to be futile and Muhammad marched again with his forces on Nishapur which forced Alauddin to shut himself inside the city walls. Muhammad recaptured Tus along with Herat and sacked the country-side.

Ghiyath al-Din Muhammad around this time died at Herat on 13 March 1203, after months of illness which briefly diverted Muhammad's attention from the existing state of affairs. Thus, taking advantage of his absence from Herat where he appointed his nephew Alp Ghazi, Khwarezmian forces captured Merv and beheaded the Ghurid governor Karang there. Muhammad of Ghor, possibly to take over the entire Khwarezmian Empire, laid siege to their capital Gurganj, instead of Herat which was besieged by the Khwarezmians after Ghiyath al-Din's death. Alauddin retreated on the Ghurid advance and desperately requested aid from the Qara Khitais, who sent a sizeable army to aid the Khwarezmians. Muhammad, because of the pressure from the Qara Khitai forces was forced to relieve the siege and retreat. However, he was chased on his way to Firuzkuh and was decisively defeated in the Battle of Andkhud in 1204 by the combined forces of Qara Khitai and Kara-Khanid Khanate under Taniku and Uthman ibn Ibrahim. He was allowed to return to his capital, after paying a heavy ransom to the Qara Khitai general Taniku (Tayangu) which included several elephants and gold coins. According to Juzjani, the negotiations between Muhammad and Taniku were arranged by Uthman ibn Ibrahim of Samarkand who do not want the "Sultan of Islam" to be captured by the infidels. Following the defeat, the Ghurids lost the control over most of the Khurasan except Herat and Balkh. Thus, Muhammad of necessity agreed for a cold peace with the Khwarezmians.