There is a report narrated by Ahmad (1691) from the hadeeth of Aboo ‘Ubaydah, who said that the last words that the Prophet (peace and blessings of Allaah be upon him) spoke were,
“Expel the Jews of the Hijaaz and Najraan from the Arabian Peninsula, and know that the most evil of people are those who took the graves of their Prophets as places of worship.”
This was classed as saheeh by al-Albaanee in al-Saheehah (no. 1132).
And Aboo Dawood (5156) and Ibn Maajah (2698) narrated that ‘Alee (may Allaah be pleased with him) said: The last words that the Messenger of Allaah (peace and blessings of Allaah be upon him) spoke were,
“The prayer, the prayer! And fear Allaah with regard to those whom your right hands possess.”
This was classed as saheeh by al-Albaanee in Saheeh Abee Dawood.
And there are other similar ahaadeeth.
What is meant by these reports is that these are some of the last things that the Prophet (peace and blessings of Allaah be upon him) said, or they were the last pieces of advice that the Prophet (peace and blessings of Allaah be upon him) gave to his family and companions, and those who would be in authority after he was gone.
These ahaadeeth are among the last things he said, but the following hadeeth of ‘Aa’ishah is the last of all.
The last words of the Prophet (peace and blessings of Allaah be upon him) – before he bade farewell to this world – were:
“O Allaah, (with) the higher companions.”
This is the title that al-Bukhaaree gave to a chapter in Kitaab al-Maghaazee in his Saheeh: “The last words of the Prophet (peace and blessings of Allaah be upon him)”, where he quoted the hadeeth of ‘Aa’ishah (may Allaah be pleased with her) who said:
When the Prophet was healthy, he used to say,
“No soul of a Prophet is taken until he has been shown his place in Paradise and then he is given the choice.”
When death approached him while his head was on my thigh, he became unconscious and then recovered consciousness. He then looked at the ceiling of the house and said,
“O Allaah! (with) the highest companions.“
I said (to myself), “He is not going to choose (to stay with) us.”
Then I understood what he meant when he said that to us when he was healthy.
The last words he spoke were,
“O Allaah! (with) the highest companions.”
[Narrated by al-Bukhaaree (4463); Muslim (2444)]
See Fayd al-Qadeer by al-Manaawee (5/250 – 251)
Note: al-Suhaylee said:
“The reason why these – ‘O Allaah, (with) the higher companions’ – were the last words of the Prophet (peace and blessings of Allaah be upon him) is because they refer both to Tawheed and to dhikr in the heart. It offers comfort to those who are unable to speak (when dying), because some people may not be able to speak out loud for some reason, but that does not matter if their hearts are steadfast in remembering Allaah.”
Quoted by al-Haafiz in al-Fath (8/138)