What should a person who joined the prayer late do, if the imam made a mistake and said the tasleem after the third rak‘ah of a four-rak‘ah prayer, then remembered and stood up to do a fourth rak‘ah?
Question

                The Imaam leading us in Isha salaat sat for final Tashahuudd after third rakah and performed both the salaam's. the imaam immediately realised the mistake and offered one raka'h after that with sah sajda. Is this correct. How to rectify the error in this kind of situation. Also kindly note that many have joined the congregation in the 2nd and 3rd raka'h. the 3rd raka'h joinees didn't know whether it's 3rd or 4th until the tashahuud and salaam and as soon as they stood up for completing the missed raka'h the imaaam also stood up few moments later.
Praise be to Allah.
	Firstly:

	If a person prays ‘Isha’ with three rak‘ahs by mistake, then 
	he says the tasleem, he should get up up to complete the prayer and say the 
	tasleem, then do the two prostrations of forgetfulness then say the tasleem 
	again, because of the report narrated by Muslim (574) from ‘Imraan ibn 
	Husayn, according to which the Messenger of Allah (blessings and peace of 
	Allah be upon him) prayed ‘Asr and said the tasleem after three rak‘ahs, 
	then he went into his house. A man called al-Khirbaaq, who had long arms, 
	stood up and said: O Messenger of Allaah! And he told him what he had done. 
	He came out looking angry, dragging his cloak, and when he reached the 
	people he said: “Is this one telling the truth?” They said: Yes. So he 
	prayed one rak‘ah, then he said the tasleem, then he prostrated twice, then 
	he said the tasleem.

	Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was 
	asked:

	If someone prays ‘Isha’ with three rak‘ahs, then he speaks or 
	walks a little, does he have to repeat the prayer or can he resume on the 
	basis of what he has already done, and do the prostration of forgetfulness?

	He replied:

	He should not repeat the prayer from the beginning; rather 
	what he must do is complete the prayer, as the Prophet (blessings and peace 
	of Allah be upon him) did in the hadith narrated by ‘Imraan ibn Husayn. … He 
	quoted the hadith, then he said: If this happens, then what the individual 
	must do is complete his prayer, then say the tasleem, then do the two 
	prostrations of forgetfulness, then say the tasleem again, as the Prophet 
	(blessings and peace of Allah be upon him) did. End quote.

	Majmoo‘ Fataawa wa Rasaa’il al-‘Uthaymeen 
	(14/58).

	Secondly:

	If one who joined the prayer late gets up to complete his 
	prayer after the imam says the tasleem, then it becomes clear to him that 
	the imam still has one rak‘ah to do, so he has got up to do it, then the one 
	who is praying behind him and joined the prayer late has the choice: if he 
	wishes he may go back and pray that rak‘ah with the imam, then get up and 
	complete what he missed of the prayer, or if he wishes he may continue with 
	his prayer on his own.

	It says in al-Durar al-Saniyyah fi’l-Ajwibah an-Najdiyyah 
	(4/333):

	Shaykh ‘Abdullah ibn ‘Abd ar-Rahmaan Abu Butayn (may Allah 
	have mercy on him) was asked: What if the imam says the tasleem following an 
	incomplete prayer, and one who joined the prayer late gets up to complete 
	what he missed, then notices the imam…?

	He replied:

	The scholars mentioned a case similar to this, which is: what 
	if the one who is praying behind the imam leaves the imam for a reason that 
	makes it permissible for him to do that, then that excuse ceases to apply 
	after he left the imam? Our view is that he has the choice between rejoining 
	the imam or completing his prayer on his own, except the author of at-Talkhees, 
	who said: He must rejoin the imam, because his excuse has ceased to apply. 
	End quote.

	Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
	

	If the imam says the tasleem before completing his prayer, 
	then the one who is praying behind him and joined the prayer late gets up to 
	complete what he missed, then the imam is told that he still has one rak‘ah 
	to do, so the imam gets up to complete the rak‘ah, then we say: the one who 
	was praying behind him is now praying on his own, on the basis of shar‘i 
	evidence, so he is excused for praying on his own. So if the imam resumes in 
	order to complete his prayer, then he has the choice: if he wishes he may 
	carry on with his own prayer, or if he wishes he may rejoin the imam.

	End quote from ash-Sharh al-Mumti‘ (2/314)

	And Allah knows best.