The Messenger of Allah (ﷺ) led his companions in offering the fear prayer. One group prayed with him while the other was facing the enemy. He led them in praying two rak'ahs, then they went and took the place of the others, and the others came and he led them in praying two rak'ahs, then he said the taslim.
Chapter 1: The narrations mentioned for the Fear Prayer - كتاب صلاة الخوف
أَخْبَرَنَا عَمْرُو بْنُ عَلِيٍّ، قَالَ حَدَّثَنَا يَحْيَى بْنُ سَعِيدٍ، قَالَ حَدَّثَنَا الأَشْعَثُ، عَنِ الْحَسَنِ، عَنْ أَبِي بَكْرَةَ، عَنِ النَّبِيِّ صلى الله عليه وسلم أَنَّهُ صَلَّى صَلاَةَ الْخَوْفِ بِالَّذِينَ خَلْفَهُ رَكْعَتَيْنِ وَالَّذِينَ جَاءُوا بَعْدُ رَكْعَتَيْنِ فَكَانَتْ لِلنَّبِيِّ صلى الله عليه وسلم أَرْبَعَ رَكَعَاتٍ وَلِهَؤُلاَءِ رَكْعَتَيْنِ رَكْعَتَيْنِ .
It was narrated from Abu Bakrah that:
The Prophet (ﷺ) offered the fear prayer with those who were behind him, praying two rak'ahs (with them) and two rak'ahs with those who came after them, so the Prophet (ﷺ) prayed four rak'ahs and the others each prayed two rak'ahs.