كتاب الإمارة
33  
The Book on Government
(42)
Chapter: One who fights so that the word of Allah will be supreme is fighting in the cause of Allah
(42)
باب مَنْ قَاتَلَ لِتَكُونَ كَلِمَةُ اللَّهِ هِيَ الْعُلْيَا فَهُوَ فِي سَبِيلِ اللَّهِ ‏‏
Sahih Muslim 1904 a

It has been narrated on the authority of Abu Musa Ash'ari that a desert Arab came to the Prophet (ﷺ) and said:

Messenger of Allah, one man fights fgr the spoils of war; another fights that he may be remembered, and another fights that he may see his (high) position (achieved as a result of his valour in fighting). Which of these is fighting in the cause of God? The Messenger of Allah (ﷺ) said: Who fights so that the word of Allah is exalted is fighting in the way of Allah.
حَدَّثَنَا مُحَمَّدُ بْنُ الْمُثَنَّى، وَابْنُ، بَشَّارٍ - وَاللَّفْظُ لاِبْنِ الْمُثَنَّى - قَالاَ حَدَّثَنَا مُحَمَّدُ، بْنُ جَعْفَرٍ حَدَّثَنَا شُعْبَةُ، عَنْ عَمْرِو بْنِ مُرَّةَ، قَالَ سَمِعْتُ أَبَا وَائِلٍ، قَالَ حَدَّثَنَا أَبُو مُوسَى، الأَشْعَرِيُّ أَنَّ رَجُلاً، أَعْرَابِيًّا أَتَى النَّبِيَّ صلى الله عليه وسلم فَقَالَ يَا رَسُولَ اللَّهِ الرَّجُلُ يُقَاتِلُ لِلْمَغْنَمِ وَالرَّجُلُ يُقَاتِلُ لِيُذْكَرَ وَالرَّجُلُ يُقَاتِلُ لِيُرَى مَكَانُهُ فَمَنْ فِي سَبِيلِ اللَّهِ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ قَاتَلَ لِتَكُونَ كَلِمَةُ اللَّهِ أَعْلَى فَهُوَ فِي سَبِيلِ اللَّهِ ‏"‏ ‏.‏
Reference : Sahih Muslim 1904a
In-book reference : Book 33, Hadith 214
USC-MSA web (English) reference : Book 20, Hadith 4684
  (deprecated numbering scheme)