كتاب المغازى
64
Military Expeditions led by the Prophet (pbuh) (Al-Maghaazi)
(84)
Chapter: The last statement, the Prophet (saws) spoke
(84)
باب آخِرِ مَا تَكَلَّمَ النَّبِيُّ صلى الله عليه وسلم
Sahih al-Bukhari 4463

Narrated `Aisha:

When the Prophet (ﷺ) was healthy, he used to say, "No soul of a prophet is captured till he is shown his place in Paradise and then he is given the option." When death approached him while his head was on my thigh, he became unconscious and then recovered his consciousness. He then looked at the ceiling of the house and said, "O Allah! (with) the highest companions." I said (to myself), "Hence, he is not going to choose us." Then I realized that what he had said was the application of the narration which he used to mention to us when he was healthy. The last word he spoke was, "O Allah! (with) the highest companion."

حَدَّثَنَا بِشْرُ بْنُ مُحَمَّدٍ، حَدَّثَنَا عَبْدُ اللَّهِ، قَالَ يُونُسُ قَالَ الزُّهْرِيُّ أَخْبَرَنِي سَعِيدُ بْنُ الْمُسَيَّبِ، فِي رِجَالٍ مِنْ أَهْلِ الْعِلْمِ أَنَّ عَائِشَةَ قَالَتْ كَانَ النَّبِيُّ صلى الله عليه وسلم يَقُولُ وَهْوَ صَحِيحٌ ‏"‏ إِنَّهُ لَمْ يُقْبَضْ نَبِيٌّ حَتَّى يَرَى مَقْعَدَهُ مِنَ الْجَنَّةِ، ثُمَّ يُخَيَّرَ ‏"‏‏.‏ فَلَمَّا نَزَلَ بِهِ وَرَأْسُهُ عَلَى فَخِذِي غُشِيَ عَلَيْهِ، ثُمَّ أَفَاقَ، فَأَشْخَصَ بَصَرَهُ إِلَى سَقْفِ الْبَيْتِ ثُمَّ قَالَ ‏"‏ اللَّهُمَّ الرَّفِيقَ الأَعْلَى ‏"‏‏.‏ فَقُلْتُ إِذًا لاَ يَخْتَارُنَا‏.‏ وَعَرَفْتُ أَنَّهُ الْحَدِيثُ الَّذِي كَانَ يُحَدِّثُنَا وَهْوَ صَحِيحٌ قَالَتْ فَكَانَتْ آخِرَ كَلِمَةٍ تَكَلَّمَ بِهَا ‏"‏ اللَّهُمَّ الرَّفِيقَ الأَعْلَى ‏"‏‏.‏
Reference : Sahih al-Bukhari 4463
In-book reference : Book 64, Hadith 479
USC-MSA web (English) reference : Vol. 5, Book 59, Hadith 740
  (deprecated numbering scheme)