Abu Hurairah reported,

The Messenger of Allah ﷺ forgot during the prayer and gave the closing salutation after only two prostrations.Dhul-Shimalayn said to him, "Has the prayer been shortened, or did you forget, Messenger of Allah?"The Messenger of Allah ﷺ asked, "Is Dhul-Yadayn telling the truth?"They replied, "Yes."So the Messenger of Allah ﷺ stood up and completed the prayer.

Nasai 1230

Sahih

أخبرنا هارون بن موسى الفروي قال حدثني أبو ضمرة عن يونس عن ابن شهاب قال أخبرني أبو سلمة

عن أبي هريرة قال

نسي رسول الله ﷺ فسلم في سجدتين فقال له ذو الشمالين أقصرت الصلاة أم نسيت يا رسول الله قال رسول الله ﷺ أصدق ذو اليدين قالوا نعم فقام رسول الله ﷺ فأتم الصلاة

النسائي 1230صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Nasai Sughra
Book
Forgetfulness
Chapter
What one should do if he gives salaam after two rakahs forgetfully and speaks
Numbering
Darussalam 1230
Nasai 1230