This occurred at about 240 AD.
They were 8 Christian men who ran away from a Roman king called داقيوس Daqius who was an idolater: he persecuted the monotheists.
At that time, Christians worshipped God alone without associate, and believed Jesus was an apostle sent by God and that he was not any son of God or God Himself.
So these Christians: the devoted to God alone, ran away from that tyrant, and resorted to a cave outside their city.
This cave is about one hour walking on feet distance from Amman in Jordan, near a village called the Rajeeb.
Near that cave was a grave yard, and at the door of the cave was a stone written on it (later on) their names.
So they resorted to that cave and prayed God to accompany them by someone to bring them their food and other needs --> so God let a shepherd accompany them together with his dog.
When they went in that cave, God made them sleep deeply together with their dog; then the king was told about them, so he came with his soldiers and saw them sleeping; so he ordered the gate of the cave be closed by building so that they would die in that cave; then he left them there and went his way.
They slept in that cave, then some years later, the king died, and things changed, and people became Christians: two parties: these two parties knew about the story of these 8 men, but they did not know about their fate: people thought they had died.
This was a miracle of God Almighty.
Then after the elapsing of the 20-30 years of their sleeping in that cave, a shepherd passed by that place, and he saw the gate built with bricks; he needed some bricks, so he started to take the bricks --> then fresh air came into that cave, and these righteous men awoke.
This is in the Quran 18: 9-26
(Or do you [Mohammed] think the Men of the Cave and the [stone] inscribed on [it their names] were among Our wonderful signs!?
When the youths resorted to the cave, and said: "Our Lord, bestow on us mercy from You and make for us our affairs easy and upright."
So We impeded [noise and sounds from reaching] their ears, [to let them sleep] in the cave, for a number of countable years [less than 30 years.]
Afterwards We raised them up, that We might know which of the two parties would give a better estimation of the time of their tarrying.
We will relate to you [Mohammed] their tidings with true [words.] They were youths who believed in their Lord, and We increased them in guidance.
And We made firm their hearts, that they rose and said: "Our Lord is the Lord of the heavens and the earth; never shall we worship any god apart from Him; [for if we did], we then should have uttered extremely false words."
"These our people have taken for worship gods apart from Him: why do they not produce an authority clear [and convincing] for those [whom they worship]? Then who does more wrong than such as invents a falsehood against God?"
So, when you have gone apart from them and that they serve, apart from God, resort to the cave, and your Lord will shower for you of His mercy, and will prepare a companion for you in your plight.)
They were 8 Christian men who ran away from a Roman king called داقيوس Daqius who was an idolater: he persecuted the monotheists.
At that time, Christians worshipped God alone without associate, and believed Jesus was an apostle sent by God and that he was not any son of God or God Himself.
So these Christians: the devoted to God alone, ran away from that tyrant, and resorted to a cave outside their city.
This cave is about one hour walking on feet distance from Amman in Jordan, near a village called the Rajeeb.
Near that cave was a grave yard, and at the door of the cave was a stone written on it (later on) their names.
So they resorted to that cave and prayed God to accompany them by someone to bring them their food and other needs --> so God let a shepherd accompany them together with his dog.
When they went in that cave, God made them sleep deeply together with their dog; then the king was told about them, so he came with his soldiers and saw them sleeping; so he ordered the gate of the cave be closed by building so that they would die in that cave; then he left them there and went his way.
They slept in that cave, then some years later, the king died, and things changed, and people became Christians: two parties: these two parties knew about the story of these 8 men, but they did not know about their fate: people thought they had died.
This was a miracle of God Almighty.
Then after the elapsing of the 20-30 years of their sleeping in that cave, a shepherd passed by that place, and he saw the gate built with bricks; he needed some bricks, so he started to take the bricks --> then fresh air came into that cave, and these righteous men awoke.
This is in the Quran 18: 9-26
أَمْ حَسِبْتَ أَنَّ أَصْحَابَ الْكَهْفِ وَالرَّقِيمِ كَانُوا مِنْ آيَاتِنَا عَجَبًا . إِذْ أَوَى الْفِتْيَةُ إِلَى الْكَهْفِ فَقَالُوا رَبَّنَا آتِنَا مِن لَّدُنكَ رَحْمَةً وَهَيِّئْ لَنَا مِنْ أَمْرِنَا رَشَدًا . فَضَرَبْنَا عَلَى آذَانِهِمْ فِي الْكَهْفِ سِنِينَ عَدَدًا ...إلخ
The explanation:
(Or do you [Mohammed] think the Men of the Cave and the [stone] inscribed on [it their names] were among Our wonderful signs!?
When the youths resorted to the cave, and said: "Our Lord, bestow on us mercy from You and make for us our affairs easy and upright."
So We impeded [noise and sounds from reaching] their ears, [to let them sleep] in the cave, for a number of countable years [less than 30 years.]
Afterwards We raised them up, that We might know which of the two parties would give a better estimation of the time of their tarrying.
We will relate to you [Mohammed] their tidings with true [words.] They were youths who believed in their Lord, and We increased them in guidance.
And We made firm their hearts, that they rose and said: "Our Lord is the Lord of the heavens and the earth; never shall we worship any god apart from Him; [for if we did], we then should have uttered extremely false words."
"These our people have taken for worship gods apart from Him: why do they not produce an authority clear [and convincing] for those [whom they worship]? Then who does more wrong than such as invents a falsehood against God?"
So, when you have gone apart from them and that they serve, apart from God, resort to the cave, and your Lord will shower for you of His mercy, and will prepare a companion for you in your plight.)