The Prophet Muhammad sallallahu `alayhi wa sallam mentioned that just before the end of this world, the Muslim nation will be ruled by a Caliphate that will follow the guidance sent with the Messenger of Allah sallallahu `alayhi wa sallam.
Hudhaifah bin Al-Yaman reported that the Messenger of Allah sallallahu `alayhi wa sallam said,
"Prophethood (meaning himself) will remain with you for as long as Allah wills it to remain, then Allahwill raise it up wherever he wills to raise it up. Afterwards, there will be a Caliphate that follows the guidance of Prophethood remaining with you for as long as Allah wills it to remain. Then, He will raise it up whenever He wills to raise it up. Afterwards, there will be a reign of violently oppressive [The reign of Muslim kings who are partially unjust] rule and it will remain with you for as long as Allah wills it to remain. Then, there will be a reign of tyrannical rule and it will remain for as long as Allah wills it to remain. Then, Allah will raise it up whenever He wills to raise it up. Then, there will be a Caliphate that follows the guidance of Prophethood."
Then Hudhaifah said, "The Prophet stopped speaking." [As-Silsilah As-Sahihah, vol. 1, no. 5]
The reason behind mentioning this Hadith here is to state that Al-Mahdi will live in the last period of rightly guided Caliphs that the Messenger of Allah sallallaahu `alayhi wa sallam mentioned himself sallallaahu `alayhi wa sallam.
In this Hadith, the Messenger of Allah divided the history of the Muslim nation into the following stages:
1. The reign of the Prophet Muhammad
2. A Caliphate that rules according to the guidance revealed to the Messenger of Allah sallallaahu `alayhi wa sallam This period is called the reign of the rightly guided Caliphs, starting with Abu Bakr, then Umar, then Uthman and ending with the murder of Ali bin Abi Talib, may Allah be pleased withthem all. Some scholars included the short reign of Al-Hasan bin Ali, the grandson of the Messenger of Allah sallallaahu `alayhi wa sallam These are the thirty years which the Messenger of Allah sallallaahu `alayhi wa sallam stated comprised the reign of the rightly guided Caliphs [The Prophet sallallaahu `alayhi wa sallam said? "The Caliphate will remain in my nation after me for thirty years. Then, it will be a monarchy after that." Ahmad, Tirmidhi and others, Sahih Al-Jami` ' As-Saghir no. 3341].
3. The reign of unjust rule. This reign contains some injustice to a varying degree between one king and another. This period started after Al-Hasan bin Ali and includes the Umayyad, Abbasid, Mamluks and until the fall of the Ottoman State in the twentieth century.
This period includes all states that ruled in the Muslim World during those centuries. However, we exclude the reign of those rulers whose rule was similar to the rule of the rightly guided Caliphs, such as the reign of Abdullah bin Az-Zubayr and Umar bin Abdul-Aziz. These two are considered among the just Caliphs from among the tribe of Quraish who ruled or will rule the Muslim nation.
4. The reign of the tyrannical rule. This period started in the end of the Ottoman state and continues. We ask Allah that He saves us from the evils of this period and that we witness its end soon.
This reign includes all the regimes that ruled the Muslim World, whether imperial, party oriented, governments controlled by the disbelievers, like those after World War I, populist or republic, which all sought to deprive Allah from His right as the Only Legislator in all matters of life and religion.
When the Messenger of Allah sallallaahu `alayhi wa sallam mentioned the periods that this nation will experience, he categorized them according to the type of government, whether unjust, or that which follows the guidance of the Prophet, or autocratic and tyrannical, as we experience today.
5. The return of a Caliphate that rules following the guidance of the Prophet sallallaahu `alayhi wa sallam This period requires the Muslims to be prepared and strive for its imminent coming, by spreading the knowledge of the Book and the Sunnah and the way of our righteous ancestors, As-Salaf As-Salih. This is because nothing can resurrect this nation except that which resurrected its ancestors. Until this final period comes, the religion will become a stranger, the same way it started in Makkah, a stranger to its masters and slaves, the powerful and the weak, its women, and its children.