The Messenger of Allah (may peace he upon him) led on* of the two groups In one rak'ah of prayer in danger, while the other group faced the -enemy. Then they (the members of the first group) went back and replaced their companions who were facing the enemy. and then they (the members of the second group) came and the Messenger of Allah ﷺ led them in one rak'ah of prayer. Then the Messenger of Allah ﷺ pronounced salutation, and then they (the members of the Ant group) completed the rak'ah and they (the members of the second group) completed the rak'ah. (Using translation from Muslim 839a)
صَلَّى رَسُولُ اللهِ ﷺ صَلَاةَ الْخَوْفِ بِإِحْدَى الطَّائِفَتَيْنِ رَكْعَةً وَالطَّائِفَةُ الْأُخْرَى مُوَاجِهَةُ الْعَدُوِّ ثُمَّ انْصَرَفُوا وَقَامُوا فِي مَقَامِ أَصْحَابِهِمْ مُقْبِلِينَ عَلَى الْعَدُوِّ وَجَاءَ أُولَئِكَ فَصَلَّى بِهِمُ النَّبِيُّ ﷺ رَكْعَةً ثُمَّ سَلَّمَ ثُمَّ قَضَى هَؤُلَاءِ رَكْعَةً وَهَؤُلَاءِ رَكْعَةً