The Turkic Muslim sedentary people of the Tarim Basin were originally ruled by the Chagatai Khanate while the nomadic Buddhist Oirat Mongol in Dzungaria ruled over the Dzungar Khanate. The Naqshbandi Sufi Khojas, descendants of the Prophet Muhammad, had replaced the Chagatayid Khans as the ruling authority of the Tarim Basin in the early 17th century. There was a struggle between two factions of Khojas, the Afaqi (White Mountain) faction and the Ishaqi (Black Mountain) faction. The Ishaqi defeated the Afaqi, which resulted in the Afaq Khoja inviting the 5th Dalai Lama, the leader of the Tibetan Buddhists, to intervene on his behalf in 1677. The 5th Dalai Lama then called upon his Dzungar Buddhist followers in the Zunghar Khanate to act on this invitation. The Dzungar Khanate then conquered the Tarim Basin in 1680, setting up the Afaqi Khoja as their puppet ruler.