عن صالح بن خَوَّاتِ بْنِ جُبَيْرٍ رضي الله عنه عمّن صلَّى مع رسول الله صلى الله عليه وسلم صلاة ذَاتِ الرِّقَاعِ صلاةَ الخوف: أن طائفة صفَّت معه، وطائفة وِجَاهَ الْعَدُوِّ، فصلَّى بالذين معه ركعة، ثم ثبت قائما، وأتموا لأنفسهم، ثم انصرفوا، فصفُّوا وِجَاهَ الْعَدُوِّ، وجاءت الطائفة الأخرى، فصلَّى بهم الركعة التي بقيت، ثم ثبت جالسا، وأتموا لأنفسهم، ثم سلَّم بهم. [صحيح] - [متفق عليه] المزيــد ...
Sālih ibn Khawwāt ibn Jubayr (may Allah be pleased with him) reported from those who performed the prayer of fear with the Messenger of Allah (may Allah's peace and blessings be upon him) in the expedition of Dhāt Ar-Riqā‘:"A group stood in rows to pray behind the Prophet while the other group stood in the enemy's direction. He prayed one Rak‘ah with the group that was with him then remained standing until they finished their prayer. Then they left and stood in rows in the enemy's direction while the second group came and the Prophet led them in the remaining Rak‘ah and remained sitting until they completed their prayer and then he performed Taslīm with them." Sahih/Authentic. - [Al-Bukhari and Muslim]
The Prophet (may Allah's peace and blessings be upon him) led his Companions in a military expedition. Most of them were walking barefoot, and when their feet became sore from walking, they wrapped rags around them. No fighting took place but the Muslims scared away their enemies.
As this Hadīth indicates, the enemies were not in the direction of the prayer as they came from the east of Madīnah. Therefore, the Prophet divided Muslims into two groups: one group stood to pray with him while the other group stood facing the direction of the enemies at the back of the praying group.
The Prophet (may Allah's peace and blessings be upon him) prayed one Rak‘ah with the group that was with him then rose for the second Rak‘ah but remained standing while they completed the second Rak‘ah and made Taslīm. They then left to stand facing the direction of the enemies while the other group came and prayed with the Prophet the second Rak‘ah. He remained sitting in the second Rak‘ah while they rose to perform one more Rak‘ah thus completing their prayer, then he made Taslīm with them.
Thus, the first group said the opening Takbīr with the Prophet while the second group said the Taslīm with him. So both groups were even, as each had the merit of praying in congregation with the Imām. At the same time, they did not give the enemy a chance to attack them while they were engaged in prayer.