The Messenger of Allah ﷺ led us in two units of prayer, then he stood up without sitting, and the people stood with him. When he finished his prayer and we awaited his closing salutation, he said the takbir, then performed two prostrations while seated before the salutation, and then he gave the closing salutation.
صلى لنا رسول الله ﷺ ركعتين، ثم قام فلم يجلس، فقام الناس معه. فلما قضى صلاته، ونظرنا تسليمه، كبر، ثم سجد سجدتين، وهو جالس قبل التسليم، ثم سلم.
Malik related it in "The Prayer" (65) from Ibn Shihab, from Araj, from Abdullah bin Buhaynah, mentioning it in similar terms.Bukhari related it in "Forgetfulness" (1224) from Abdullah bin Yusuf, and Muslim in "Mosques" (570) from Yahya bin Yahya, both of them from Malik with the same wording.Malik related it (66) from Yahya bin Saeed, from Abdul-Rahman bin Hurmuz, from Abdullah bin Buhaynah, stating that it was the Dhuhr prayer. Bukhari related it (1225) from Abdullah bin Yusuf, from Malik with the same wording. Muslim related it through another route from Yahya bin Saeed with the same wording.Tirmidhi related it (391) from Qutayba bin Saeed, who said, Layth narrated it to us with the same wording, and it contained, "When he completed his prayer, he prostrated two prostrations, saying the takbir in each prostration while sitting, before saying the salam, and the people prostrated with him in place of the sitting he had forgotten."Tirmidhi said, "The practice among some scholars is based on this. It is the view of Shafii, who holds that both prostrations of forgetfulness should always be before the salam, and he says, this is the abrogating narration relative to the other hadiths, and he mentions that the Prophet's ﷺ last action was according to this."Then he conveyed the statement of Imam Ahmad, "As for what has been narrated from the Prophet ﷺ concerning the two prostrations of forgetfulness, each narration is to be applied according to its own context. He holds that if one stands up after two rakahs, following the hadith of Ibn Buhaynah, he should prostrate before the salam, but if he prays Dhuhr as five rakahs, he should prostrate after the salam, and if he says the salam after two rakahs in Dhuhr or Asr, he should prostrate after the salam. Each case is applied according to its own circumstance. And for any instance of forgetfulness for which nothing has been reported from the Prophet ﷺ, the two prostrations of forgetfulness are to be done before the salam."Ishaq held a view similar to that of Ahmad in all of this, except that he said, for any instance of forgetfulness for which nothing has been reported from the Prophet ﷺ, if it involved an addition to the prayer, the two prostrations are done after the salam, and if it involved an omission, they are done before the salam.He also mentioned the view of the people of Kufa and of Thawri, that the two prostrations of forgetfulness are always done after the salam.