The twelfth Imām in the Golden Chain was Imām Muḥammad ibn Ḥasan ʿalaihi as-salām, son and successor of Imām Ḥasan ʿAskarī. His epithet was Abu’l-Qāsim. He was born in the month of Shaʾbān 255 or 256 AH in Sāmarrā, Iraq. He was about five years old when his father passed away.
There is a difference of opinion in the scholars of Ahl as-Sunnah whether he was the twelfth Imām in the Golden Chain, or whether the promised Mahdī will be the twelfth Imām. The great Naqshbandī master and author Mawlānā ʿAbd ar-Raḥmān Jāmī calls him the twelfth Imām [Shawāhid an-Nubuwwah]. He is also called Imām Muḥammad al-Mahdī, although he is different than the promised Mahdī (see below).
A person came to visit his father Imām Ḥasan ʿAskarī and asked him: O son of the Prophet! Who will be the Imām and successor after you? The Imām went inside his home and brought a child on his shoulders, who was about three years old and shining like a full moon. He said to the visitor: If you were not from the distinguished servants of Allāh, I would not have shown you my child. His name is the name of the Messenger of Allāh ṣall-Allāhu ʿalaihi wa-sallam (i.e., Muḥammad).
Shaykh ʿAlāʾ ad-Dawla Aḥmad ibn Muḥammad Simnānī says that Imām Muḥammad ibn Ḥasan went into hiding for some time, during which he became an Abdāl, and later acquired the post of Quṭb after the death of the then Quṭb ʿAlī ibn Ḥusayn Baghdādī. He remained a Quṭb for thirty years and died in Madīnah, and was succeeded (as Quṭb) by ʿUthmān ibn Yaʿqūb Khurāsānī [Shawāhid an-Nubuwwah].
Note that in the Ahl as-Sunnah creed, the promised Imām Mahdī is not the same as Imām Muḥammad ibn Ḥasan. According to the majority of Sunni scholars, the promised Mahdī will be born in the end of times and will unite the whole Ummah and bring the whole world under Islamic rule. He will kill Dajjāl with the help of Prophet ʿĪsā ʿalaihi as-salām. His name will be Muḥammad and his title will be Abu’l-Qāsim, and he will be from the progeny of Imām Ḥasan ibn ʿAlī ibn Abī-Ṭālib [Bārā Imām].