The Twelve Imams are the spiritual and political successors to the Islamic prophet Muhammad in the Twelver or Ithna-‘ashariyyah branch of Shia Islam. According to the theology of Twelvers, the Twelve Imams are infallible human individuals who not only ruled over the community with justice, but also were able to keep and interpret sharia and the esoteric meaning of the Quran. Muhammad and Imams' words and deeds are a guide and model for the community to follow; as a result, they must be free from error and sin, and must be chosen by divine decree, or nass, through the Prophet. It is believed by Twelver Shia Muslims that the Twelve Imams were foretold in the Hadith of the Twelve Successors.
It is believed in Twelver and Ismaili Shia Islam that ‘aql, divine wisdom, was the source of the souls of the Prophets and Imams and gave them esoteric knowledge called ḥikmah and that their sufferings were a means of divine grace to their devotees. Although the Imam was not the recipient of a divine revelation, he had a close relationship with God, through which God guides him, and the Imam in turn guides the people. The Imams were also guided by secret texts in their possession, such as al-Jafr and al-Jamia. Imamate, or belief in the divine guide is a fundamental belief in the Twelver and Ismaili Shia branches and is based on the concept that God would not leave humanity without access to divine guidance.
According to Twelvers, there is always an Imam of the Age, who is the divinely appointed authority on all matters of faith and law in the Muslim community. Ali was the first of the Twelve Imams, and, in the Twelvers' view, the rightful successor to Muhammad, followed by male descendants of Muhammad through his daughter Fatimah. Each Imam was the son of the previous Imam, with the exception of Husayn ibn Ali, who was the brother of Hasan ibn Ali. The twelfth and final Imam is Muhammad al-Mahdi, who is believed by the Twelvers to be currently alive, and hidden in the Major Occultation until he returns to bring justice to the world. All of the Imams met unnatural deaths, with the exception of the last Imam.