Abu Hurairah reported,

The Messenger of Allah ﷺ prayed one day and gave the closing salam after only two units, then he turned away. Dhul-Shimalayn caught up with him and said, "Messenger of Allah, has the prayer been shortened, or did you forget?"He replied, "The prayer has not been shortened, nor did I forget."Dhul-Shimalayn said, "Yes indeed, by the One who sent you with the truth."The Messenger of Allah ﷺ asked, "Has Dhul-Yadayn spoken truthfully?"They answered, "Yes."So he led the people in two more units of prayer.

Nasai 1229

Sahih

أخبرنا عيسى بن حماد قال حدثنا الليث عن يزيد بن أبي حبيب عن عمران بن أبي أنس عن أبي سلمة

عن أبي هريرة

أن رسول الله ﷺ صلى يوما فسلم في ركعتين ثم انصرف فأدركه ذو الشمالين فقال يا رسول الله أنقصت الصلاة أم نسيت فقال لم تنقص الصلاة ولم أنس قال بلى والذي بعثك بالحق قال رسول الله ﷺ أصدق ذو اليدين قالوا نعم فصلى بالناس ركعتين

النسائي 1229صحيح
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 1229
Nasai 1229