The Twelve Imams are the spiritual and political successors to Muhammad, the Prophet of Islam, in the Twelver or Ithna-‘ashariyyah branch of Shī‘ah Islam. According to the theology of Twelvers, the successor of Muhammad is an infallible human individual who not only rules over the community with justice, but also is able to keep and interpret the Divine Law:
(Sharia (Arabic: 'شريعة transliteration: Šarīʿah) is the body of Islamic religious law. The term means "way" or "path to the water source"; it is the legal framework within which the public and private aspects of life are regulated for those living in a legal system based on Islamic principles of jurisprudence and for Muslims living outside the domain. Sharia deals with many aspects of day-to-day life, including politics, economics, banking, business, contracts, family, sexuality, hygiene, and social issues.)
and its esoteric meaning. The Prophet and Imams' (Sunnah) 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 in Twelver and Ismaili Shī‘ah Islam:
(Ismāʿīlism (Urdu: إسماعیلی Ismāʿīlī, Arabic: الإسماعيليون al-Ismāʿīliyyūn; Persian: إسماعیلیان Esmāʿiliyān) is a branch of the Islamic faith, and is the second largest part of the Shī‘ah community, after the mainstream Twelvers (Ithnāʿashariyya). The Ismāʿīlī get their name from their acceptance of Ismāʿīl ibn Jaʿfar as the divinely appointed spiritual successor (Imām) to Jaʿfar aṣ-Ṣādiq, wherein they differ from the Twelvers, who accept Mūsà al-Kāżim, younger brother of Ismāʿīl, as the true Imām).
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. Imamate, or belief in the divine guide is a fundamental belief in the Twelver and Ismaili Shī‘ī 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. ‘Alī was the first Imam of this line, and in the Twelvers' view, the rightful successor to the Prophet of Islam, followed by male descendants of Muhammad through his daughter Fatimah Zahra. 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 till he returns to bring justice to the world.