The Messenger of Allah ﷺ led them in the prayer of fear. One row stood in front of him and another row behind him. He prayed one rakah and two prostrations with those behind him, then this group moved forward until they stood in the position of their companions, and the other group came forward and took the position of the first. The Messenger of Allah ﷺ then prayed one rakah and two prostrations with them, and gave the salam. So the Prophet ﷺ performed two rakahs, while each group performed one.
أخبرنا إبراهيم بن الحسن عن حجاج بن محمد عن شعبة عن الحكم عن يزيد الفقير
أن رسول الله ﷺ صلى بهم صلاة الخوف فقام صف بين يديه وصف خلفه صلى بالذين خلفه ركعة وسجدتين ثم تقدم هؤلاء حتى قاموا في مقام أصحابهم وجاء أولئك فقاموا مقام هؤلاء وصلى بهم رسول الله ﷺ ركعة وسجدتين ثم سلم فكانت للنبي ﷺ ركعتان ولهم ركعة
[Sahih] Reported by Ahmad, 3/298, from the hadith of Shuba through this same chain. It is also found in Kubra, hadith 1933, and Ibn Khuzayma graded it sahih, hadith 1347, 1348. It has many corroborating narrations.Hakam bin Utayba is corroborated by Misar bin Kidam as found in Ibn Khuzayma.