How should one who has caught up with the congregation in the last rak’ah of Maghrib complete his prayer?
Question

Suppose we are in Magrib prayer and we joined the salat from the second rakat ie from the Tashahud part., then how shall I complete my prayers. Like I normally stand after the salam complete one rakat sit for Tashahud and then complete the third rakat and complete the Tashahud.
Praise be to Allah.If you join the congregation during the first tashahhud of Maghrib prayer, then you should follow the imam in the third rak’ah, and recite the tashahhud, then get up after he says the salaam to complete your prayer. You have two rak’ahs left, so pray the first one with al-Faatihah and another soorah, then recite the tashahhud, which is the first tashahhud for you, then get up for the third rak’ah, and recite al-Faatihah only, and recite the last tashahhud, then say the salam. 
What is stated above is based on the assumption that what the latecomer caught up with with the imam is the beginning of his own prayer, and what he prays on his own is the end of his prayer. This is the opinion of al-Shafi’i (may Allaah have mercy on him). 
Al-Nawawi (may Allaah have mercy on him) said in al-Majmu’ (4/117): If he catches up with a rak’ah of Maghrib he should stand up after the imam says the salam and pray one rak’ah and recite the tashahhud, then pray a third rak’ah and recite the tashahhud. 
Then he said: 
We have mentioned that our view is that what the latecomer catches up with is the first part of his prayer and what he makes up is the last part. This is the view of Sa’id ibn al-Musayyib, al-Hasan al-Basri, ‘Ata, ‘Umar ibn ‘Abd al-‘Azoz, Makhul, al-Zuhri, al-Awza’i, Sa’id ibn ‘Abd al-‘Aziz and Ishaq. Ibn al-Mundhir narrated it from them and said: This is also my opinion. He said: and it was narrated from ‘Umar, ‘Ali and Abu’l-Darda, but that is not proven. It was also narrated from Malik and was the view of Dawud. 
Abu Hanifah, Malik, al-Thawri and Ahmad said: What he caught up with is the latter part of his prayer and what he makes up is the first part of his prayer. This was narrated by Ibn al-Mundhir from Ibn ‘Umar, Mujahid and Ibn Sirin. They quoted as evidence for that the words of the Prophet (peace and blessings of Allah be upon him), “Whatever you catch up with, pray, and whatever you have missed, make it up.” Narrated by al-Bukhari and Muslim. Our companions quoted as evidence the words of the Prophet (peace and blessings of Allah be upon him): “Whatever you catch up with, pray, and whatever you have missed, complete it.” Narrated by al-Bukhari and Muslim with many isnads. 
Al-Bayhaqi said: Those who narrated the words “complete it” are greater in number, have better memories and are closer to Abu Hurayrah who is the narrator of this hadith, so they are more correct. Shaykh Abu Hamid and al-Mawirdi said: Completing a thing can only be done after doing the first part of it. Al-Bayhaqi also narrated a view similar to ours from ‘Umar ibn al-Khattab, ‘Ali, Abu’l-Darda, Ibn al-Musayyib, Hasan, ‘Ata, Ibn Sirin and Abu Qilabah (may Allah be pleased with them). 
With regard to the report which says “make it up.” This may be answered in two ways: 
1 – That those who narrated the words “complete it” are greater in number and have better memories 
2 – That qada (the word translated here as “make it up”) is actually to be interpreted as meaning “do it” and not the usual sense in which the word is understood, because this usage is that of the later fuqaha, whereas the Arabs used the word in the sense of doing. Allah says (interpretation of the meaning): 
“So when you have accomplished [qadaytum] your Manasik (rituals of Hajj)”
[al-Baqarah 2:200] 
“When you have finished [qudiyat] As-Salah (the congregational prayer)”
[al-Nisa 4:103]
Shaykh Abu Hamid said: What is meant is: what you have missed of your own prayer, not what you missed of the imam’s prayer; what the latecomer has missed of his own prayer is the latter part of it. 
It says in Fatawa al-Lajnah al-Daimah (7/322): 
Question: I would like to know more about how a latecomer should pray: 
1-If the imam has already prayed one or two rak’ahs of Maghrib
2-If the imam has already prayed one or two rak’ahs of a four-rak’ah prayer.
What should he recite? Should he recite al-Fatihah only or another soorah as well? 
Answer:  
Whatever the latecomer catches up with of the prayer with his imam is regarded as the first part of his prayer. So whoever catches up with one rak’ah of Maghrib, that is regarded as being the first part of his prayer. So he should stand up after the imam says the salam and make up what he missed. In the first rak’ah he makes up he should recite al-Fatihah and another surah or verses, because it is the second rak’ah for him. Then he should sit and recite the first tashahhud. Then when he stands up to make up the remaining rak’ah of Maghrib he should recite al-Fatihah only, because it is the third rak’ah for him. Then he should sit and recite the final tashahhud. If what he missed of Maghrib was one rak’ah, and he caught up with two rak’ahs with the imam, then he should recite al-Fatihah only in the last rak’ah that he makes up after the imam says the salam, because it is the third rak’ah for him.  
If it is a four-rak’ah prayer and he catches up with three or two rak’ahs with the imam, then he should recite al-Fatihah only in the one or two rak’ahs that he makes up, because that is the latter part of the prayer for him, so he does not have to recite another surah as well as al-Fatihah. This is the correct scholarly view. And Allah is the Source of strength. May Allah send blessings and peace upon our Prophet Muhammad and his family and Companions. 
Standing Committee for Academic Research and Issuing Fatwas.  
And Allah knows best.