The Messenger of Allah ﷺ stood up at the even rakah in which he had meant to sit during his prayer, and he continued on with his prayer. Then, at the end of the prayer, he prostrated before giving the salutation, and afterward he gave the salutation.
و حدثنا أبو الربيع الزهراني حدثنا حماد حدثنا يحيى بن سعيد عن عبد الرحمن الأعرج
أن رسول الله ﷺ قام في الشفع الذي يريد أن يجلس في صلاته فمضى في صلاته فلما كان في آخر الصلاة سجد قبل أن يسلم ثم سلم