The Mahdi, "the rightly guided one", is the figure expected to appear before the end of time and fill the earth with justice as it has been filled with injustice. The title is not used in this technical sense in the Qur'an; the expectation rests on hadith, collected in Abu Dawud, Ibn Maja and al-Tirmidhi rather than in the two most rigorously graded collections, and the tradition has consequently held it with varying degrees of firmness.
Twelver Shia Islam gives the expectation its most developed form. The Mahdi is identified with a specific person, Muhammad al-Mahdi, the twelfth Imam, held to have been born in 869 and to have entered concealment, the lesser occultation from 874, the greater from 941, and to be living, hidden, and the rightful authority in the world until his return. Almost the whole structure of Twelver religious authority follows from this: because the Imam is absent, qualified jurists act in his name, a logic that runs from the medieval deputyship to the modern office of the marja and to twentieth-century arguments over clerical rule. Ismaili Shia traditions developed their own imamate and their own eschatological figures.
Sunni Islam widely expects a Mahdi not yet born, of the Prophet's family, who will appear alongside the descent of Jesus. But the expectation sits more loosely: the hadith are graded variously, some scholars have questioned them, and Ibn Khaldun devoted a long and sceptical section of the Muqaddima to examining the chains of transmission. Claimants have been numerous and consequential, the Fatimid founder Abdallah al-Mahdi, Ibn Tumart of the Almohads, Muhammad Ahmad in the Sudan in 1881, and, in 1979, the group that seized the Grand Mosque at Mecca proclaiming one of their number Mahdi. Mainstream scholarship in both branches has generally treated the identification of any living person as the Mahdi with deep suspicion.