The World Federation One Stop Fiqh

Ruling 1092

If a person forgets the salām of the prayer and remembers it before the form of the prayer has broken up, and if he has neither intentionally nor inadvertently done something that would invalidate his prayer – such as turning his back to qibla – then he must say the salām and his prayer is valid.