I prayed behind an imam who usually makes the tasleem lengthy, hence I got up to complete what I had missed of the prayer whilst he was still saying the words “wa rahmat Allah”. Is my prayer valid?

On one occasion I was praying, and when saying the tasleem, there was a slip of the tongue and I pronounced it wrong, but I quickly repeated it right away, when my head was still turned to the right. Is my prayer valid? Or do I have to do the prostration of forgetfulness (sujood as-sahw)?

Praise
be to Allah

Firstly: 

The salaam is one of the pillars or essential parts of the
prayer, and one of its obligatory actions, without which it is not valid.
This is the view of the majority of scholars among the Sahaabah and
Taabi‘een, and those who came after them.

End quote from Sharh an-Nawawi ‘ala Muslim (5/83)

The majority of scholars are of the view that the second
tasleem at the end of the prayer is mustahabb. Imam Ahmad and some of the
Maalikis are of the view that it is obligatory.

Ibn Qudaamah (may Allah have mercy on him) said:

What is obligatory is one tasleem; the second is Sunnah. Ibn
al-Mundhir said: All of the scholars from whom I acquired knowledge are
unanimously agreed that the prayer of one who says only one tasleem is
acceptable. Al-Qaadi said: There is another report concerning that, which
says that the second is obligatory. And he said: It (the second report) is
more correct, because of the hadith of Jaabir ibn Samurah, and because the
Prophet (blessings and peace of Allah be upon him) used to do that
consistently; because it is an act of worship that has two things required
to exit from it, so they are obligatory, like the two stages that are
required for exiting ihram in Hajj; and because it is one of the two
tasleems, so it is obligatory like the first one.

End quote from al-Mughni (1/369)

Please see also questions no. 105297
and 119604

in al-Mawsoo‘ah al-Fiqhiyyah (37/163) it says:

The Maalikis said:

The one who joined the prayer late should stand up to make up
what he missed after his imam says the salaam. If he stands up for that
purpose before the imam says the salaam, his prayer is rendered invalid.

The Shaafa‘is said:

It is mustahabb for one who joined the prayer late not to
stand up to complete the rest of his prayer until after the imam has
finished the two tasleems. If he stands up after he has finished saying
“as-salaamu ‘alaykum” for the first tasleem, that is acceptable, because he
has finished saying the first one. But if he stands up before the imam
starts saying the two tasleems, his prayer is rendered invalid. If he stands
up after the imam has started to say the salaam, but before he has finished
saying “ ‘alaykum”, then it is as if he stood up before he started saying
it.

The Hanbalis said:

The one who joined the prayer late should stand up to make up
what he missed after his imam has finished saying the second (tasleem). If
he stands up before the imam says the salaam, and does not sit back down so
that he may stand up after he has said the salaam, his prayer becomes naafil
(supererogatory). End quote.

An-Nawawi (may Allah have mercy on him) said:

Our companions are unanimously agreed that it is mustahabb
for the one who joined the prayer late not to stand up in order to complete
the rest of his prayer until after the imam has finished saying the two
tasleems. Among those who stated this clearly were al-Baghawi and al-Mutawalli,
and others. This was stated by ash-Shaafa‘i (may Allah have mercy on him) in
Mukhtasar al-Buwayti. He said: Whoever joins the prayer late should
not stand up to make up whatever he has missed until after the imam has
finished saying the two tasleems. Our companions said: But if he gets up
after the imam has finished saying “as-salaamu ‘alaykum” for the first
tasleem, that is acceptable, because he has exited the prayer thereby.

End quote from al-Majmoo‘ (3/483)

He also said:

Once the imam has said the first tasleem, the one who is
praying behind him – whether he prayed with him from the beginning or joined
the prayer late – is no longer obliged to follow him, because he has exited
the prayer.

End quote from al-Majmoo‘ (3/484)

Ibn ‘Abd al-Barr (may Allah have mercy on him) said:

Al-Layth said concerning one who joins the prayer late:

I do not see anything wrong with him standing up after the
first tasleem.

End quote from al-Istidhkaar (1/489)

Based on that:

If you stand up for the second rak‘ah after the imam has
finished saying “as-salaamu ‘alaykum” in the first tasleem, then your prayer
is valid according to the view of the majority, but it is invalid according
to the well-known view of the Hanbalis, and you have to repeat the prayer.

The view of the majority is more correct, in sha Allah,
especially with regard to past prayers, because of the difference of opinion
concerning it and the fact that so many said that the prayer in such cases
is valid, to the extent that it was reported that there was consensus.
However what you should do is to be more careful in the future with regard
to the prayer, and not exit the prayer until after you are certain that it
has ended and the imam has said the second tasleem. 

However, if you stood up for the second rak‘ah after the imam
had said “as-salaamu ‘alaykum” for the second tasleem, then your prayer is
valid, and there is scholarly consensus on that. 

Secondly:

With regard to what you mentioned about you making a mistake
in the pronunciation of the tasleem, there is no blame on you for that, in
sha Allah, especially since you made up for it by pronouncing it correctly
at the right time.

And Allah knows best.