The Messenger of Allah ﷺ prayed one rakah with one of the two groups while the other group faced the enemy. Then they departed and took the place of the others, and the others came forward, and he prayed another rakah with them and gave the salam. Then this group stood and completed their remaining rakah, and the other group stood and completed their remaining rakah.
أخبرنا إسمعيل بن مسعود عن يزيد بن زريع قال حدثنا معمر عن الزهري
أن رسول الله ﷺ صلى بإحدى الطائفتين ركعة والطائفة الأخرى مواجهة العدو ثم انطلقوا فقاموا في مقام أولئك وجاء أولئك فصلى بهم ركعة أخرى ثم سلم عليهم فقام هؤلاء فقضوا ركعتهم وقام هؤلاء فقضوا ركعتهم
Bukhari narrated it in the Book of Military Expeditions, Chapter on the Battle of Dhat al-Riqa, hadith no. 4133, from the hadith of Yazid bin Zuray, and Muslim narrated it in the Book of the Prayer of Travelers, Chapter on the Prayer of Fear, hadith no. 839, from the hadith of Mamar through the same chain, and it is in Al-Kubra, hadith no. 1928.