Abdullah bin Umar reported,

The Messenger of Allah ﷺ became forgetful and gave the closing salutation after only two rak'ahs. A man known as Dhul-Yadayn said to him, "Messenger of Allah, has the prayer been shortened, or have you forgotten?"He replied, "It has not been shortened, nor have I forgotten."Dhul-Yadayn said, "Then you have prayed only two rak'ahs."The Prophet ﷺ asked the others, "Is it as Dhul-Yadayn says?"They answered, "Yes."So he stepped forward and prayed two more rak'ahs, then gave the closing salutation, and then performed two prostrations for forgetfulness.

Ibn Majah 1213

Sahih

حدثنا علي بن محمد وأبو كريب وأحمد بن سنان قالوا حدثنا أبو أسامة عن عبيد الله بن عمر عن نافع

عن ابن عمر

أن رسول الله ﷺ سها فسلم في الركعتين فقال له رجل يقال له ذو اليدين يا رسول الله أقصرت أم نسيت قال ما قصرت وما نسيت قال إذا فصليت ركعتين قال أكما يقول ذو اليدين قالوا نعم فتقدم فصلى ركعتين ثم سلم ثم سجد سجدتي السهو

ابن ماجه 1213صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Establishing prayer and the sunnah regarding it
Chapter
Regarding one who gave salaam after two or three rakaat forgetfully
Numbering
Darussalam 1213
Ibn Majah 1213