In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
Answering your question, Sheikh Kifah Mustapha, the Imam and Director of The Prayer Center of Orland Park and representative for Dar El Fatwa of Lebanon in the US, states:
According to the School of Shafi`iyyah, you can do that with the condition that both the Imam and the one behind him must match in movements.
Now in your case, because the number of rak`as of Maghrib are shorter than those of `Isha’, you can either stay on your last rak`ah’s tashahhud sitting and waiting for Imam to make his fourth rak`ah and then join him the last tashahhud, or you can finish your prayer in your third rak`ah by making tasleem. Then, you offer `Isha’ prayer.
Almighty Allah knows best.
Editor’s note: This fatwa is from Ask the Scholar’s archive and was originally published at an earlier date.