After his father Tekish died, Muhammad succeeded him. Right after his accession, however, his domains were invaded by the two Ghurid brothers Ghiyas ad-Din Ghori and Mu'izz al-Din. Within weeks, the two brothers had moved their armies westwards into Khorasan. Once they had captured Nishapur, Mu'izz al-Din was sent on an expedition towards Ray, but he let his troops get out of control and got little further than Gurgan, earning criticism from Ghiyas which led to the only reported quarrel between the brothers.
Ghiyas died at Herat in 1202 after months of illness. Muhammad II used this opportunity to invade the domains of the Ghurid Empire, and besieged Herat. Mu'izz, however, managed to repel him from Herat and then pursued him to Khwarezm, besieging Gurganj, his capital. Muhammad desperately requested aid from the Kara-Khitan Khanate, who sent an army to aid Muhammad. Mu'izz, because of the pressure from the Kara-Khitans, was forced to relieve the siege and retreat. However, on his way to his domains in Ghur, he was defeated at Andkhud in 1204. Mu'izz al-Din was later assassinated in 1206, throwing the Ghurid Empire into a civil war. During the civil war, Ghiyath al-Din Mahmud managed to emerge victorious.
However, Ghiyath's Turkic general Tajuddin Yildoz seized Ghazni from the Ghurid rulers of Bamiyan, but shortly recognized the authority of Ghiyath. Ghiyath, not glad about Tajuddin controlling Ghazni, and not daring to leave Ghur unprotected, requested help from the Muhammad II. Muhammad, however, instead invaded the domains of Ghiyath, capturing Balkh and Tirmidh. However, during his invasion he was captured by the Kara-Khitan Khanate. Thirteen months later, Muhammad was freed from captivity, and once again invaded the domains of Ghiyath, and captured Herat. Muhammad then invaded the Ghurid heartland of Ghur, and captured Ghiyath. Ghiyath then agreed to recognize Muhammad's authority.
Muhammad II then captured Samarkand (captured by Karakhanids in 1208) in 1207 from the Kara Khitay, Tabaristan in 1210 from Bavandids and Transoxiana from Western Karakhanids. He pursued expansionist policy and conquered Tashkent and Fergana from Western Karakhanids and regions of Makran and Balochistan from Ghurids and Atabegs of Azerbaijan become his vassals in 1211. He finally destroyed Western Karakhanids in 1212 and Ghurids in 1215 annexing with their remainder territories. During 1212 the city of Samarkand revolted killing 8,000–10,000 Khwarezmians living there. Muhammad, in retaliation, sacked the city and executed 10,000 citizens of Samarkand.
By 1217, he had conquered all the lands from the river Jaxartes to the Persian Gulf. He declared himself shah and demanded formal recognition from the caliph in Baghdad. When the caliph an-Nasir rejected his claim, Ala ad-Din Muhammad gathered an army and marched towards Baghdad to depose an-Nasir. However, when crossing the Zagros Mountains, the shah's army was caught in a blizzard. Thousands of warriors died. With the army decimated, the generals had no choice but to return home.