Harith reported,

The Prophet ﷺ said, "Allah commanded Yahya bin Zakariya with five words, that he should act upon them and command the Children of Israil to act upon them as well. But he was almost slow in delivering them, so Isa said to him, 'Allah commanded you with five words, that you act upon them and command the Children of Israil to act upon them. Either you command them, or I will command them.'"Yahya replied, 'I fear that if you get ahead of me in this, I will be swallowed up by the earth, or punished.'"So he gathered the people in Bayt al-Maqdis until the masjid was full and people were sitting on the balconies, and he said, 'Allah has commanded me with five words, that I act upon them and command you to act upon them."'The first is that you worship Allah and associate nothing with Him. The likeness of one who associates partners with Allah is that of a man who bought a slave with his own pure wealth, in gold or silver, and said to him, "This is my house and this is my work. Work and hand over the proceeds to me." But the slave worked and handed over the proceeds to someone other than his master. Which of you would be pleased to have a slave like that?"'Allah commands you to pray, and when you pray do not turn away, for Allah sets His face toward the face of His servant during his prayer as long as he does not turn away."'And I command you to fast, for the likeness of that is a man in a company of people with a pouch of musk with him. Every one of them delights in its fragrance. And the breath of the fasting person is sweeter to Allah than the scent of musk."'And I command you to give charity, for the likeness of that is a man captured by the enemy. They bound his hand to his neck and brought him forward to strike off his head, and he said, "I will ransom myself from you with everything I have, little and much," and so he ransomed himself from them."'And I command you to remember Allah, for the likeness of that is a man whose enemies came after him in swift pursuit until he reached a fortified stronghold and saved himself from them. In the same way, a servant cannot protect himself from Satan except through the remembrance of Allah.'"The Prophet ﷺ then said, "And I command you with five that Allah has commanded me with. Listening, obedience, jihad, migration, and holding to the community. Whoever separates from the community by so much as a handspan has cast off the yoke of Islam from his neck, unless he returns. And whoever makes the calls of the days of ignorance is among the throngs of Hell."A man asked, "Messenger of Allah, even if he prays and fasts?"He replied, "Even if he prays and fasts. So call by the call of Allah, who named you Muslims, believers, servants of Allah."

Tirmidhi 2864

Sahih

حدثنا محمد بن بشار حدثنا أبو داود الطيالسي حدثنا أبان بن يزيد عن يحيى بن أبي كثير عن زيد بن سلام عن أبي سلام عن الحارث الأشعري عن النبي ﷺ نحوه بمعناه

الترمذي 2864صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Parables
Chapter
Likeness of prayer, fasting, and charity
Numbering
Darussalam 2864
Tirmidhi 2864