Changing the Intention of Prayer with the Imam

Question
I entered the mosque to perform the Maghrib prayer in congregation, and I found the imam concluding the prayer. Then he announced that he would pray the Isha prayer combined with Maghrib due to the rain. I intended to pray Maghrib following the imam who is praying Isha, and I concluded my prayer after the third rak'ah while the imam stood for the fourth rak'ah. Is what I did correct?
Answer
I say, and with God's help: The prayer is not valid between the imam and the follower if they differ, as in the situation you mentioned, and you must repeat the Maghrib prayer; for it is invalid due to the intention of praying after the Isha prayer, and God knows best.
imam icon

Send your question to the smart assistant

If the previous answers are not appropriate, please send your question to the Mufti via