This article discusses the matter about Prophet Muhammad’s last words. Although there are a number of reports on this, the following hadith of Ayesha (R) is considered more authentic and final in this regard.
Ayeshah (may Allah be pleased with her) 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 Allah! (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 Allah! (with) the highest companions.”’ Narrated by al-Bukhaari, 4463; Muslim, 2444.
There are other reports about some of the other last words of Prophet Muhammad (saws) as well. For example, according to one of the reports the Messenger of Allah (peace and blessings of Allah be upon him) said, “The prayer, the prayer! And fear Allah with regard to those whom your right hands possess.” This was classed as saheeh by al-Albaani in Saheeh Abi Dawood.(Fayd al-Qadeer by al-Manaawi, 5/250 – 251 – as quote in islamqa.info)
However, the earlier mentioned hadith of Ayesha is considered as the most authentic in terms of the ‘prophet’s last words’.