The prayer of fear is performed as follows. The imam stands with one group of his companions while another group faces the enemy. The imam performs one cycle of prayer, bowing and prostrating with those who are with him, then he stands up. Once he is fully upright, he remains standing while they complete the remaining cycle on their own, then they give the closing salutation and depart, while the imam continues standing. They then take up position facing the enemy.The other group, who had not yet prayed, then come forward and say the opening takbir behind the imam. He bows and prostrates with them, then gives the closing salutation. They stand up and perform the remaining cycle on their own, then give the closing salutation.
حدثنا القعنبي عن مالك عن يحيى بن سعيد عن القاسم بن محمد عن صالح بن خوات الأنصاري
أن صلاة الخوف أن يقوم الإمام وطائفة من أصحابه وطائفة مواجهة العدو فيركع الإمام ركعة ويسجد بالذين معه ثم يقوم فإذا استوى قائما ثبت قائما وأتموا لأنفسهم الركعة الباقية ثم سلموا وانصرفوا والإمام قائم فكانوا وجاه العدو ثم يقبل الآخرون الذين لم يصلوا فيكبرون وراء الإمام فيركع بهم ويسجد بهم ثم يسلم فيقومون فيركعون لأنفسهم الركعة الباقية ثم يسلمون
Agreed upon (Bukhari and Muslim), see the previous hadith. It is also in Muwatta (Yahya): 1/183, 184.