The story of the three men who sought refuge in a cave, were shut in by a rock, and were delivered when they implored Allah through their righteous deeds
Imam al-Bukhari relates:
“Ismāʿīl ibn Khalīl narrated to us, saying: ‘ʿAlī ibn Mus-hir informed us, from ʿUbaydullāh ibn ʿUmar, from Nāfiʿ, from Ibn ʿUmar, that the Messenger of Allah ﷺ said:
‘Three men from those who lived before you were travelling when rain overtook them, so they entered a cave for shelter. A boulder then rolled down and blocked the entrance.
They said to one another, “By Allah, nothing will save you now except honesty. Let each of you call upon Allah with the deed he knows he performed sincerely for His sake.”
One of them said, “O Allah, You know that I once hired a labourer for a measure of rice. He left without taking his wages, so I planted that rice and, from its yield, I bought cattle. After some time he came to claim his pay. I said, ‘Take those cattle and drive them away.’ He replied, ‘All I am owed by you is a measure of rice.’ I told him, ‘Take the cattle, for they all came from that single measure.’ He took them and left. O Allah, if I did this seeking only Your pleasure, relieve us of what we face.” The rock shifted a little.
The second said, “O Allah, You know that I had two elderly parents. Each night I would bring them milk from my flock. One night I was delayed, and when I arrived they were asleep, while my wife and children were crying from hunger. I would not give them any milk before my parents drank, yet I disliked waking them and I disliked leaving them without their share. I stood there with the vessel in my hand, waiting for them to wake, until dawn broke. O Allah, if I did that out of fear of You, relieve us.” The rock moved further, and they could see the sky.
The third said, “O Allah, You know that I had a female cousin who was the dearest of people to me. I sought to commit sin with her, but she refused unless I brought her one hundred dīnārs. I laboured until I collected the amount, brought it to her, and she allowed me access to herself. When I sat between her legs she said, ‘Fear Allah, and do not break the seal except in its lawful way.’ So I rose, left her, and allowed her to keep the hundred dīnārs. O Allah, if I did that out of fear of You, relieve us.”
Allah then removed the rock completely, and they walked out.’”