It is narrated from Sayyiduna Ibn Umar (may Allah be pleased with them both) that the Noble Prophet (peace and blessings be upon him) led them in the prayer of fear (Salat al-Khawf). He led one group, who were standing behind him, in one rak'ah, while another group was standing facing the enemy. Then the group who had prayed got up and stood facing the enemy, and the other group came forward. The Noble Prophet (peace and blessings be upon him) led them in one rak'ah as well, then he said the salam. After that, both groups completed their prayer by praying one rak'ah each.
So, after the first group has finished the first rak‘ah, the second group is permitted to abandon facing the qiblah in order to protect against the enemy—and the explanation of both groups completing the second rak‘ah after the imam has said the salām.
Hadith Referenceصحيح ابن خزيمه / جماع أبواب صلاة الخوف / 1354