Muhammad Ahmad was a religious teacher from Dongola who had already gathered a following as a Sufi ascetic before he declared himself the Mahdi in June 1881, the rightly guided figure Islamic eschatology holds will appear before the end of days to restore justice on earth. His call went out as jihad, first against the Ottoman Egyptian administration that governed Sudan in the name of the Khedive, then, as his Ansar followers grew, against the British officers who staffed that administration's military and civil posts, among them the general Charles Gordon.
The Ansar took Khartoum in January 1885 after a ten month siege, killing Gordon in the assault, and Muhammad Ahmad died of typhus only months later, leaving the state he had founded to his chosen successor, the Khalifa Abdallahi ibn Muhammad. Abdallahi ruled for thirteen years, defending Mahdist Sudan against rival claimants and neighboring powers alike, until a British and Egyptian army under Lord Kitchener destroyed his forces at the Battle of Omdurman in September 1898 and killed him at Umm Diwaykarat the following year. Sudan was then administered as an Anglo Egyptian condominium, formally ending the Mahdist state, though in practice, despite that nominally joint status, effective authority rested with British officials for the following half century, a legacy of the war that shaped Sudanese politics through independence in 1956.