Origin 700 to 874 CE
A figure expected to appear before the end of time and to fill the earth with justice as it has been filled with injustice. The term is not in the Quran. Beyond the bare expectation, the three principal accounts have little in common and should not be merged.
In Twelver Shia doctrine the Mahdi is a specific historical person, Muhammad ibn al-Hasan, the twelfth Imam, born in 869 and in occultation since 874, alive, hidden, and to return. This is a matter of faith rather than of expectation, it is bound up with the doctrine of the imamate, and the long absence generated the theory of authority by which qualified scholars act in the Imam's stead, which is the basis of the marjaiyya and, in one twentieth-century reading, of clerical government.
In Sunni belief the Mahdi is not yet born and is not identified. He is expected as a descendant of the Prophet who will appear at a time of crisis, be acclaimed at the Kaaba, and rule for a period before or alongside the return of Jesus and the defeat of the Dajjal. The reports are in the Sunan collections rather than in Bukhari and Muslim, and their status has been questioned: Ibn Khaldun in the fourteenth century examined the chains and found most of them weak, and a body of modern Sunni scholarship treats the doctrine as popular expectation rather than a required article of faith.
In Ahmadi belief the awaited Mahdi and the promised Messiah were one person and have already come: Mirza Ghulam Ahmad, who died in 1908 and who claimed the office. That claim is the principal reason Ahmadis are rejected as Muslims by the other groups and are legally excluded from Islam in Pakistan.
Claimants have appeared repeatedly, and the seizure of the Grand Mosque in Mecca in 1979 by a group proclaiming one of their number the Mahdi is the most consequential modern instance.