Imam Ibn Baaz was asked:

Question:

If the intention of the Imam and the one behind him are different, is the prayer correct?

He replied:

الصواب أنها صحيحة؛ لأن الرسول -صلى الله عليه وسلم- صلى في الخوف ببعض المسلمين ركعتين صلاة الخوف، ثم صلى بالطائفة الأخرى ركعتين،

What is correct is that it [i.e. the prayer] is correct because the prophet صلى الله عليه و سلم prayed two Rakats in the [prayer] of fear with some Muslims, then he prayed with another group of them two Rakats.

فصارت الأولى له فريضة، والثانية له نافلة وهم لهم فريضة، وكان معاذ -رضي الله عنه- يصلي مع النبي -صلى الله عليه وسلم- في العشاء صلاة الفريضة،

Thus the first for him [صلى الله عليه و سلم] was an obligation and the second one voluntary whilst for them it was obligatory, and Muath Ibn Jabal radiallahu Anhu used to pray with the prophet صلى الله عليه و سلم Isha, an obligatory prayer

ثم يرجع ويصلي بقومه صلاة العشاء نافلةً له وهي لهم فرض، فدل ذلك على أنه لا حرج في اختلاف النية،

Then he would return and pray with his people the Isha prayers as being voluntary for him [i.e. it was voluntary for Muath] while for them it was an obligation. Thus, that indicates upon that there is no problem in the intentions being different.

Translated by

Majid Jawed Al-Afghanee
Abu Layl