Background
He was a son of Ali ibn Abi Talib, the first Shi'ite Imam and the fourth Sunni Caliph. Muhammad ibn al-Hanafiyyah (Muhammad Akbar) was born in Medina about 633 CE (though also said to be during Umar's era), the third of Ali's sons. He was called Ibn al-Hanafiyyah after his mother, Khawlah bint Ja'far.
She was known as Hanafiyyah, "the Hanafi woman", after her tribe Banu Hanifah.
Career
After Husayn ibn Ali. When her tribesmen found out, they approached Ali ibn Abi Talib and asked him to save her from slavery and to protect her family’s honor and prestige. Consequently, Ali ibn Abi Talib purchased her, set her free, and, after the death of Fatimah, married her.
Muhammad ibn al-Hanafiyyah was the only child of Khawlah bint Ja'far. During his father's lifetime he distinguished himself for piety, rectitude, and courage and effectiveness in war. During Ali's caliphate at Kufa he was one of the caliph's four chief lieutenants.
He particularly distinguished himself at the battles of Jamal and Siffin. Husayn replied that he feared that if he stayed in Mecca, Yazid ibn Muawiya would have him killed there, and violate the sanctity of the Holy City. Muhammad ibn al-Hanifiyyah then urged him to go instead to Yemen, where he could indefinitely elude an army.
It was in his name that Al-Mukhtar rebelled in Kufa in 686 CE. Ibn al-Hanafiyyah was called "the Mahdi," "the rightly-guided," which then was simply a pledge of confidence in his knowledge, character, and judgment over those of the rival caliphs. In 692 CE he traveled to Damascus and swore allegiance to Abd al-Malik. In 700 he died in Medina, but thereafter a legend grew up that he was not dead, but living in seclusion on Mount Radwa near Medina, protected and fed by wild animals, and that he would, in God's good time, return to establish justice and true religion in the world.
Thus arose the legend of the Mahdi as savior. This man's son Abu'l-Abbas Abdullah as-Saffah became the first Abbasid caliph, repudiating Shi'ism, which effectively extinguished the sect that had recognized Muhammad ibn al-Hanafiyyah as an imam. His ancestors and family tree.
Membership
He is a member of Ahl al Bayt (the household of Muhammad) and Ahl al Kisa.