The last words of the Messenger of Allah ﷺ were, "The prayer, the prayer. Fear Allah regarding those whom your right hands possess."
كان آخر كلام رسول الله ﷺ: الصلاة الصلاة، اتقوا الله فيما ملكت أيمانكم.
Reported by Abu Dawud (5156), Ibn Majah (2698), Ahmad (585), Bukhari in Adab al-Mufrad (50), and Bayhaqi (11/8), all of them from the hadith of Muhammad bin Fudayl, from Mughira, from Umm Musa, from Ali, and he mentioned it. Its chain is hasan because of Umm Musa, who was Ali's concubine. It was said her name was Fakhita, and it was said Habiba. Mughira bin Miqsam Dubai narrated from her. Daraqutni said, her hadith is sound, her hadith is cited for corroboration. Ajli said, she was a trustworthy Kufan successor.A similar meaning was also narrated from Ali, who said, the Messenger of Allah ﷺ ordered me to bring him a tablet on which he would write something so that his nation would not go astray after him. He said, I feared that his life would leave him before I could act, so I said, I memorize and retain well. He said, "I enjoin the prayer, zakat, and those whom your right hands possess." Reported by Ahmad (693) from Bakr bin Isa Rasibi, who said, Umar bin Fadl told us, from Nuaym bin Yazid, from Ali bin Abu Talib, and he mentioned it. In it is Nuaym bin Yazid, who is unknown, and no one narrated from him except Umar bin Fadl. Abu Hatim said, he is unknown.On this subject there is also a report from Umm Salama that the Messenger of Allah ﷺ used to say during the illness in which he died, "The prayer, and those whom your right hands possess," and he kept saying it until his tongue could no longer utter it clearly. Reported by Ibn Majah (1625), Ahmad (26657, 26727), and Abu Yaala (6979), all of them from the hadith of Hammam, from Qatada, from Salih Abu Khalil, from Safina, from Umm Salama, and she mentioned it. Its narrators are trustworthy, but there is a break in it, for Salih Abu Khalil, who is Ibn Abu Maryam Dubai, their freedman, his narration from Safina is disconnected. However, Hammam's narration from Qatada is more sahih than Sulayman Taymi's narration from Qatada, from Anas, which is coming next.Ibn Abu Hatim said, I asked my father and Abu Zura about a hadith narrated by Mutamir bin Sulayman, from his father, from Qatada, from Anas, who said, most of the Messenger of Allah's ﷺ final instruction, when death came to him, was, "The prayer, and those whom your right hands possess." My father said, we consider this to be a mistake, and the sahih version is the hadith of Hammam, from Qatada, from Salih Abu Khalil, from Safina, from Umm Salama, from the Prophet ﷺ. And there is a break in it as mentioned before. Abu Zura said, Saeed bin Abu Aruba narrated it saying, from Qatada, from Safina, from Umm Salama, from the Prophet ﷺ. He said, Ibn Abu Aruba has better memory, but Hammam's hadith is more likely correct, since Hammam added a man to the chain. End of quote from Ilal (110/1–111).As for the hadith of Saeed bin Abu Aruba, it was reported by Ahmad (26483, 26684) and Nasai in Kubra (7061) through his route from Qatada, that Safina, the freedman of Umm Salama, narrated from Umm Salama, and he mentioned it. Nasai said, Qatada did not hear it from Safina.As for the hadith of Anas, it was reported by Ibn Majah (2697), Ahmad (12169), and Ibn Hibban (6605), all of them from the hadith of Sulayman Taymi, from Qatada, from Anas, who said, the last instruction of the Messenger of Allah ﷺ, which he uttered in his death rattle in his chest and which his tongue could barely manage to pronounce, was, "The prayer, the prayer, fear Allah regarding those whom your right hands possess." As mentioned before, Abu Hatim said that this is a mistake.As for Hakim (57/3), he reported it by this same route, but he dropped "Qatada" between Sulayman and Anas, making it directly from Sulayman to Anas. Nasai said, Sulayman Taymi did not hear this hadith from Anas, Kubra (7057). Then Nasai reported it in Kubra (7059) from the hadith of Sulayman, from Qatada, from a companion of his, from Anas, with similar wording. In it there is an unnamed man, and this is the flaw in this chain.In summary, both the hadith of Umm Salama and the hadith of Anas are not free from some flaw, but the hadith of Ali bin Abu Talib supports both of them.