In around 250 CE there ruled a Roman king called Daqyanoos (Decius) who would annually hold a gathering dedicated to the worshipping of idols. Many people would attend, dressed in their best clothing. However, one youth believed in the oneness of Allah (ﷻ), the teachings of Isa (عليه السلام) and shunned pagan worship. He rebelled against the practices that were happening in the society. He attracted another youth and then another to form a small group.
When the king heard of their rebellion he became very angry and issued a command for them to be killed. In order to save their iman (faith) they fled and went into hiding. On their escape route they met a young farmer who owned a dog; they gave him da'wah, he accepted and decided to also join them. Eventually they came to a cave in which they made dua to Allah (ﷻ) for ease. They decided to take rest there for a while, leaving the dog (named Qitmir) near the entrance as a guard. Allah (ﷻ) caused them and the dog to sleep for 300 years.
Allah (ﷻ) describes their sleeping in the Holy Quran in Surah Kahf: "You would have thought they were awake, though they lay asleep. We turned them over, to the right and the left, with their dog stretching out its forelegs at the entrance. If you had seen them, you would turn and run away, filled with fear of them." [18:18]
The Quran further states that the period of time these sleepers spent in the cave was 300 years during which the calendar of their people was changed from solar to lunar and, as a result, the period of their sleep was 309 years.
When they woke up, they had no idea they slept for centuries and thought they had only slept a few hours. When they sent one of them to buy food, the shopkeeper was amazed to see such old coins and the reality of the time they had spent in the cave gradually came to light. The present ruling king, whom some scholars have identified as Tandoosees, was a believer who came on foot to see them and seek their blessings. When these young men died they were buried in the cave along with their dog. The bones of these youth and the dog are visible to see inside.