عن عائشة أم المؤمنين رضي الله عنها قالت: كان رسولُ اللهِ صلى الله عليه وسلم يقولُ وهو صحيحٌ: “إنه لم يقبض نبيٌ قطُّ  حتى يرى مقعدَه من الجنةِ، ثم يُخيَّرُ.” فلما نزل به ورأسُه على فخذي غُشِيَ عليه ساعةً، ثم أفاق فأَشْخصَ بصرَه إلى السقفِ، ثم قال: ”اللهم الرفيقَ الأعلى.” قلتُ :  إذًا لا يختارُنا، وعَرَفتُ أنه الحديثُ الذي كان يحدثُنا به ، قالت: فكانت تلك آخرُ كلمةٍ تكلمَ بها النبيُّ صلى الله عليه وسلم قولُه: “اللهم الرفيقَ الأعلى.” صحيح البخاري حديث ٦٥٠٩ - صحيح مسلم حديث ٢٤٤٤

Narrated `Aisha: (the wife of the Prophet) When Allah’s Messenger (ﷺ) was in good health, he used to say, “No prophet’s soul is ever captured unless he is shown his place in Paradise and given the option (to die or survive).” So when the death of the Prophet (ﷺ) approached and his head was on my thigh, he became unconscious for a while and then he came to his senses and fixed his eyes on the ceiling and said, “O Allah (with) the highest companions.” (See Qur'an 4:69). I said’ “Hence he is not going to choose us.” And I came to know that it was the application of the narration which he (the Prophet) used to narrate to us. And that was the last statement of the Prophet (before his death) i.e., “O Allah! With the highest companions.” (See Qur'an 4:69). Sahih al-Bukhari 6509
In-book reference : Book 81, Hadith 98
USC-MSA web (English) reference : Vol. 8, Book 76, Hadith 516

Sahih Muslim 2444 e
In-book reference : Book 44, Hadith 127
USC-MSA web (English) reference : Book 31, Hadith 5990