The Messenger of Allah ﷺ led one of the two groups in praying one rak'ah while the other group was facing the enemy, then they moved away and took the place of the others, and the others came and he led them in praying the other rak'ah, then he said the salam and they stood up and made up the other rak'ah, and the others stood up and made up the other rak'ah.
أَنَّ رَسُولَ اللَّهِ ﷺ صَلَّى بِإِحْدَى الطَّائِفَتَيْنِ رَكْعَةً وَالطَّائِفَةُ الأُخْرَى مُوَاجِهَةُ الْعَدُوِّ ثُمَّ انْطَلَقُوا فَقَامُوا فِي مَقَامِ أُولَئِكَ وَجَاءَ أُولَئِكَ فَصَلَّى بِهِمْ رَكْعَةً أُخْرَى ثُمَّ سَلَّمَ عَلَيْهِمْ فَقَامَ هَؤُلاَءِ فَقَضُوا رَكْعَتَهُمْ وَقَامَ هَؤُلاَءِ فَقَضُوا رَكْعَتَهُمْ