The Messenger of Allah ﷺ led them in the prayer of fear. One row stood behind him while another row faced the enemy. He prayed one rakah with those behind him, then they moved away and the others came forward, and he prayed one rakah with them. Then both groups stood and completed one rakah each on their own.
أخبرنا عمرو بن علي قال حدثنا يحيى قال حدثنا شعبة عن عبد الرحمن بن القاسم عن أبيه عن صالح بن خوات
أن رسول الله ﷺ صلى بهم صلاة الخوف فصف صفا خلفه وصفا مصافو العدو فصلى بهم ركعة ثم ذهب هؤلاء وجاء أولئك فصلى بهم ركعة ثم قاموا فقضوا ركعة ركعة
Bukhari narrated it in the Book of Military Expeditions, chapter on the Battle of Dhat al-Riqa, hadith 4131, from the hadith of Yahya Qattan. Muslim narrated it in the Book of the Prayer of Travelers, chapter on the prayer of fear, hadith 841, from the hadith of Shubah through the same chain. It is also found in Al-Kubra, hadith 1924.