Sunnah.com reference : Book 2, Hadith 401English translation : Book 2, Hadith 474Arabic reference : Book 2, Hadith 476
Narrated Ibn 'Umar (RA):
I went on an expedition with Allah's Messenger (ﷺ) to Najd, and when we came in front of the enemy we lined up in ranks facing them. Allah's Messenger (ﷺ) then stood up and led us in prayer. One group stood up with him while the other faced the enemy. He prayed a Rak'ah with those who were with him and made two prostrations. Then, they changed places with those who had not prayed. When they came Allah's Messenger (ﷺ) prayed a Rak'ah with them and made two prostrations. He then uttered the Taslim (salutation) and each of them got up and prayed a Rak'ah alone and made two prostrations.

[Agreed upon, and the wording if from al-Bukhari].
وَعَنِ ابْنِ عُمَرَ قَالَ: { غَزَوْتُ مَعَ اَلنَّبِيِّ ‏- صلى الله عليه وسلم ‏-قِبَلَ نَجْدٍ, فَوَازَيْنَا اَلْعَدُوَّ, فَصَافَفْنَاهُمْ, فَقَامَ رَسُولُ اَللَّهِ ‏- صلى الله عليه وسلم ‏-يُصَلِّي بِنَا, فَقَامَتْ طَائِفَةٌ مَعَهُ, وَأَقْبَلَتْ طَائِفَةٌ عَلَى اَلْعَدُوِّ, وَرَكَعَ بِمَنْ مَعَهُ, وَسَجَدَ سَجْدَتَيْنِ, ثُمَّ انْصَرَفُوا مَكَانَ اَلطَّائِفَةِ الَّتِي لَمْ تُصَلِّ فَجَاءُوا, فَرَكَعَ بِهِمْ رَكْعَةً, وَسَجَدَ سَجْدَتَيْنِ, ثُمَّ سَلَّمَ, فَقَامَ كُلُّ وَاحِدٍ مِنْهُمْ, فَرَكَعَ لِنَفْسِهِ رَكْعَةً, وَسَجَدَ سَجْدَتَيْنِ }  مُتَّفَقٌ عَلَيْهِ، وَهَذَا لَفْظُ اَلْبُخَارِيِّ  1‏ .‏‏1 ‏- صحيح.‏ رواه البخاري (942)‏، ومسلم (839)‏.‏