All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The Imam who sits for Tashahhud in the third Rak'ah of a four-Rak'ah Prayer should rise to perform the fourth Rak'ah if he remembers or if reminded, whether that is before Tasleem or after that as long as there is a short time between Tasleem and his remembrance. The evidence is the Hadeeth reported by Al-Bukhaari and Muslim, that “The Prophet concluded a four-Rak'ah Prayer after two Rak'ahs and Dhul-yadayn told him, “Has the Prayer been shortened (to two Rak'ahs) or you just forgot, O Messenger of Allah!’ The Prophet then asked people, “Is Dhul-yadayn right?” They said, “Yes”. The Prophet then rose, prayed another two Rak'ahs and made Tasleem. He then said, “Allahu Akbar” and prostrated as he used to do or longer than that.”
Allah knows best.