كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(19)
Chapter: As-Sahw (forgetfulness) in prayer and prostrating to compensate for it
(19)
باب السَّهْوِ فِي الصَّلاَةِ وَالسُّجُودِ لَهُ ‏
Sahih Muslim 570 c

'Abdullah b. Malik ibn Buhaina al-Asadi reported:

The Messenger of Allah (ﷺ) stood up (at the end of two rak'ahs) when he had to sit and proceeded on with the prayer. But when he was at the end of the prayer, he performed a prostration before the salutation and then pronounced the salutation.
وَحَدَّثَنَا أَبُو الرَّبِيعِ الزَّهْرَانِيُّ، حَدَّثَنَا حَمَّادٌ، حَدَّثَنَا يَحْيَى بْنُ سَعِيدٍ، عَنْ عَبْدِ الرَّحْمَنِ الأَعْرَجِ، عَنْ عَبْدِ اللَّهِ بْنِ مَالِكٍ ابْنِ بُحَيْنَةَ الأَزْدِيِّ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَامَ فِي الشَّفْعِ الَّذِي يُرِيدُ أَنْ يَجْلِسَ فِي صَلاَتِهِ فَمَضَى فِي صَلاَتِهِ فَلَمَّا كَانَ فِي آخِرِ الصَّلاَةِ سَجَدَ قَبْلَ أَنْ يُسَلِّمَ ثُمَّ سَلَّمَ ‏.‏
Reference : Sahih Muslim 570c
In-book reference : Book 5, Hadith 109
USC-MSA web (English) reference : Book 4, Hadith 1165
  (deprecated numbering scheme)