Following the communist coup in 1978, Ahmadzai returned to Afghanistan to join the mujahideen. He was a close associate of Burhanuddin Rabbani, being deputy of his Jamiat-e Islami party, but then left and joined Abdul Rasul Sayyaf's Islamic Dawah Organisation of Afghanistan party in 1992, the year that communist rule ended. He served as a minister in the post-communist Afghan government, variously as interior, construction and education minister, and later became prime minister between 1995 and 1996, although he has downplayed the import of these posts given the chaos due to the fighting at that time.[3]
Ahmadzai left Afghanistan in 1996 after the government fled the Taliban advance. He lived in exile in Istanbul and London, before he returned to Afghanistan in 2001 after the fall of Taliban.[3] He was an independent candidate in the 2004 Afghan presidential election supporting an Islamic system of government.[3] He secured 0.8% of the total votes counted.[4]