Messenger of Allah (S) said: "When he commits Hadath - meaning a man - and he is sitting in the end of his Salat before saying the Taslim, then his Salat is acceptable." (Using translation from Tirmidhī 408)
"إذا أحدث - يعنى الرجل - وقد جلس في آخر صلاته قبلَ أن يسلِّم فقد جازت صلاته".