Where the story is told
This story is not in the Quran. It is an authentic hadith that the Prophet ﷺ told about people from earlier times. It is narrated by Abdullah ibn Umar and is found in Sahih al-Bukhari (2272, 3465 and 5974, with a similar version in 2215 and 2333) and in Sahih Muslim 2743.
The wording differs a little between the narrations, for example in the order of the three supplications and some small details. The meaning is the same. Here we follow the order found in Sahih al-Bukhari 5974 and Sahih Muslim 2743.
The rock closes the cave
The Prophet ﷺ said that three men were walking when rain overtook them, so they took shelter in a cave in the mountain. A rock from the mountain fell over the mouth of the cave and closed it on them. They said to one another to look at righteous deeds they had done for Allah and to call on Allah by them, hoping that He would free them.
In another narration, one of them says that nothing will save them except truthfulness, so each should pray by something in which he knows he was truthful (Sahih al-Bukhari 3465). In another, they say that nothing will save them from the rock except to call on Allah by their righteous deeds (Sahih al-Bukhari 2272).
The first man: kindness to his parents
The first man said that he had two very old parents, and that he also had small children for whom he used to graze animals. When he came back, he milked and gave his parents the milk first, before his children. One day the trees took him far away and he returned late at night to find them asleep. He milked as usual and stood by their heads, not wanting to wake them and not wanting to give the children first, while the children were crying at his feet. He stayed that way until dawn.
Then he said: O Allah, if You know that I did this seeking Your face, then open for us an opening through which we can see the sky. Allah opened a gap for them until they could see the sky.
The second man: leaving a sin out of fear of Allah
The second man said that he had a cousin whom he loved as deeply as men love women. He asked her for herself, but she refused unless he brought her one hundred dinars. He worked until he had gathered them and came to her. When he was about to commit the sin with her, she said: O servant of Allah, fear Allah, and do not break the seal except by right. He got up and left her. He said: O Allah, if You know that I did this seeking Your face, then open for us more. Allah opened a further part of the opening for them.
Some narrations mention a different sum, such as one hundred and twenty dinars in Sahih al-Bukhari 2272. In another narration, he says he did this from fear of Allah (Sahih al-Bukhari 3465).
The third man: giving the worker his full due
The third man said that he hired a worker for a measure of rice. When the worker had finished, he asked for his wage, but the man offered it to him and the worker left it and went away. The man kept planting with that measure until he had gathered cows and a herdsman from it. Later the worker came and said: Fear Allah and do not wrong me, give me my right.
The man told him to go to those cows and their herdsman. The worker said: Fear Allah and do not mock me. The man replied: I am not mocking you, take the cows and the herdsman. The worker took them and went away. Then the man said: O Allah, if You know that I did this seeking Your face, then open for us what is left. Allah opened the rest, and they came out (Sahih al-Bukhari 5974; Sahih Muslim 2743).
What the hadith does not tell us
The hadith does not give the names of the three men, their people, the place of the cave or how long they were inside. We should not add details that are not in the text. What matters is the message: each man relied only on a deed he had done sincerely for Allah.
Lessons from this story
- Sincerity is the basis of every deed. Each man said that he did his act seeking the face of Allah, and Allah opened the way for them.
- Calling on Allah through one's own righteous deeds is a legitimate form of dua. Scholars cite this hadith as evidence for it.
- Kindness to parents has great weight with Allah. The first man put his parents before his own children and was willing to wait all night rather than wake them.
- Leaving a sin out of fear of Allah, when it is within reach, is a great deed. The second man left it when his cousin reminded him to fear Allah.
- Giving people their full rights, and more, is part of faith. The third man preserved and increased the worker's wages and gave all of them back.
- Hard moments are a time to turn to Allah. The three men did not lose hope but looked for what they could offer Him sincerely.
General information for learning, not a fatwa. For your own situation, ask a qualified scholar.
Sources
- Sahih al-Bukhari 2272
- Sahih al-Bukhari 3465
- Sahih al-Bukhari 5974
- Sahih Muslim 2743