Ashab al-kahf and Ashaab al-raqeem were signs from Allah, youth, fleeing from a corrupt king, took refuge in the cave, whose story follows, then in supplicating to Allah Most High, said, O Lord, give to us specially from yourself means of mercy, and prepare for us in our task means of excellence. There is an account in Islam about pious people, and are known as "People of the Cave" (Ashab Al-Kahf). Allah Says in Qur'an.Surah Al-Kahf 18:9-26: “And they stayed in their Cave three hundred years adding nine.” The story tells of the falling asleep of young men in a cave, who wake up after a great deal of time has passed.
The people of Al-Kahf and Ar-Raqim were a wonder among Our signs! meaning, their case was not something amazing compared to power and ability of Allah, for the creation of the heavens and earth, the alternation of night and day and the subjugation of the sun, moon and heavenly bodies, and other mighty signs indicate the great power of Allah and show that He is able to do whatever He wills. He is not incapable of doing more amazing things than the story of the people of the Cave.
They were sons of the kings and leaders of Byzantium, and that they went out one day to one of the festivals of their people. They used to gather once a year outside the city, and they would worship idols and offer sacrifices to them. They had an arrogant, tyrannical king who was called Decianus, who commanded and encouraged the people to do that. When the people went out to attend this gathering, these young men went out with their fathers and their people, and when they saw their people's actions with clear insight, they realized that the prostrations and sacrifices the people were offering to their idols should only be dedicated to Allah, Who created the heavens and the earth.
Each of them started to withdraw from his people and keep aloof from them. The first one of them to move away on his own went and sat in the shade of a tree, then another came and sat with him, then another came and sat with them, then four more followed suit one by one. None of them knew the others, but they were brought together by the One Who instilled faith in their hearts.
Some of the scholars mentioned that when Allah caused them to sleep, their eyelids did not close, lest disintegration took hold of them. If their eyes remained open to the air, this would be better for the sake of preservation.
Allah tells His Messenger the length of time the people of the Cave spent in their cave, from the time when He caused them to sleep until the time when He resurrected them and caused the people of that era to find them. The length of time was three hundred plus nine years in lunar years, which is three hundred years in solar years.
Or have you thought that the companions of the cave and the inscription were, among Our signs, a wonder? [Mention] when the youths retreated to the cave and said, "Our Lord, grant us from Yourself mercy and prepare for us from our affair right guidance." So We cast [a cover of sleep] over their ears within the cave for a number of years. Then We awakened them that We might show which of the two factions was most precise in calculating what [extent] they had remained in time.
It is We who relate to you, [O Muhammad], their story in truth. Indeed, they were youths who believed in their Lord, and We increased them in guidance. And We made firm their hearts when they stood up and said, "Our Lord is the Lord of the heavens and the earth. Never will we invoke besides Him any deity. We would have certainly spoken, then, an excessive transgression.
These, our people, have taken besides Him deities. Why do they not bring for [worship of] them a clear authority? And who is more unjust than one who invents about Allah a lie?" The youths said to one another], "And when you have withdrawn from them and that which they worship other than Allah , retreat to the cave. Your Lord will spread out for you of His mercy and will prepare for you from your affair facility."
And [had you been present], you would see the sun when it rose, inclining away from their cave on the right, and when it set, passing away from them on the left, while they were [laying] within an open space thereof. That was from the signs of Allah . He whom Allah guides is the [rightly] guided, but he whom He leaves astray - never will you find for him a protecting guide.
And you would think them awake, while they were asleep. And We turned them to the right and to the left, while their dog stretched his forelegs at the entrance. If you had looked at them, you would have turned from them in flight and been filled by them with terror. And similarly, We awakened them that they might question one another. Said a speaker from among them, "How long have you remained [here]?" They said, "We have remained a day or part of a day." They said, "Your Lord is most knowing of how long you remained. So send one of you with this silver coin of yours to the city and let him look to which is the best of food and bring you provision from it and let him be cautious. And let no one be aware of you.
Indeed, if they come to know of you, they will stone you or return you to their religion. And never would you succeed, then - ever." And similarly, We caused them to be found that they [who found them] would know that the promise of Allah is truth and that of the Hour there is no doubt. [That was] when they disputed among themselves about their affair and [then] said, "Construct over them a structure. Their Lord is most knowing about them." Said those who prevailed in the matter, "We will surely take [for ourselves] over them a masjid."
They will say there were three, the fourth of them being their dog; and they will say there were five, the sixth of them being their dog - guessing at the unseen; and they will say there were seven, and the eighth of them was their dog. Say, [O Muhammad], "My Lord is most knowing of their number. None knows them except a few. So do not argue about them except with an obvious argument and do not inquire about them among [the speculators] from anyone." Quran Surah Kahf 18: 9-22  
Abu al-Darda’ reported the prophet (ﷺ) as saying : If anyone memorizes ten verses from the beginning of surat al-Kahf, he will be protected from the trial of Dajjal (Antichrist).
Abu Dawud said: In this way Hashim al-dastawa’I transmitted it from Qatadah, but he said : “If anyone memorizes the closing verses of surat al-Kahf.” Shu’bah narrated from Qatadah the words “from the end of al-Kahf. Classed as Sahih sheikh Albani in Sunan Abi Dawud 4323
Abu Darda' reported Allah's Apostle (ﷺ) as saying: If anyone learns by heart the first ten verses of the Surah al-Kahf, he will be protected from the Dajjal. Sahih Muslim 809 (Book 4, Hadith 1766)
Abu Sa’eed al-Khudri, who said: “Whoever reads Surah al-Kahf on the night of Jumu’ah, will have a light that will stretch between him and the Ancient House (the Ka’bah).”
The four main stories of this Surah are:
All these four stories, if we ponder on them really hard, actually revolves around the main theme of trials. The first story which talks about the believing youths and the disbeliever King who wanted to prosecute them for believing in Islam. This is a story that shows us how faith or religion can be a trial to us. Whereas in the second story, it tells us about how wealth can also become a trial to a person. The story of the two men and the two gardens portrays to us how one can become haughty due to his abundance of wealth and offsprings which finally led him to disbelieve in the Day of Judgement. The story of the Prophet Moses and al-Khidr represents the trial that one can face regarding his/her knowledge and the last story of Dhul-Qarnayn is talking about the trial of power.
Ibn Abbas said: "The Quraysh sent An-Nadr bin Al-Harith and Uqbah bin Abi Mu`it to the Jewish rabbis in Al-Madinah, and told them: `Ask them (the rabbis) about Muhammad, and describe him to them, and tell them what he is saying. They are the people of the first Book, and they have more knowledge of the Prophets than we do.'
They (the rabbis) said, `Ask him about three things which we will tell you to ask, and if he answers them then he is a Prophet who has been sent (by Allah); if he does not, then he is saying things that are not true, in which case how you will deal with him will be up to you.