He prayed the prayer of fear with the Messenger of Allah ﷺ. The Messenger of Allah ﷺ prayed two units with one of the two groups, then prayed two units with the other group. So the Messenger of Allah ﷺ prayed four units in total, and each group prayed two units with him.
و حدثنا عبد الله بن عبد الرحمن الدارمي أخبرنا يحيى يعني ابن حسان حدثنا معاوية وهو ابن سلام أخبرني يحيى أخبرني أبو سلمة بن عبد الرحمن أن
أنه صلى مع رسول الله ﷺ صلاة الخوف فصلى رسول الله ﷺ بإحدى الطائفتين ركعتين ثم صلى بالطائفة الأخرى ركعتين فصلى رسول الله ﷺ أربع ركعات وصلى بكل طائفة ركعتين