Allah has narrated the story of Musa Alaihis salam and Khidr in Surat Al-Kahf (ayat 60-82).
One day, Musa Alaihis salam delivered such an impressive sermon that all who heard it were deeply moved. Someone in the congregation asked: “O Messenger of Allah, Who is the greatest in knowledge?” Musa Alaihis salam replied: “I!”, believing so, as Allah had given him the power of miracles and honored him with the Torah. However, Allah revealed to Musa Alaihis salam that there is a slave at the junction of the two seas who is more knowledgeable than you. Musa asked Allah: “My lord! Tell me how could I find him? I would like to meet him and learn from him.” So Allah instructed him to take a live fish in a water-filled vessel. Where the fish disappeared, he would find the man he sought.
Musa Alaihis salam set out on his journey, accompanied by a young man Joshua bun nun, who carried the vessel with the fish. They reached a place where two rivers met and decided to rest there and fell to sleep. While Musa Alaihis salam was sleeping, the fish wriggled out of the vessel into the river and swam away. However, when he woke up, his attendant forgot to relate this incident to him and they continued their journey for the rest of the day and that night.
Next day Musa Alaihis salam asked for his morning meal. Only then did his companion recall that the fish they had brought with them had gotten away. Hearing this, Musa Alaihis salam exclaimed: ‘This is exactly what we are seeking!” They hurriedly retraced their steps to the place where the rivers met and where the fish had jumped out. There they found a man wrapped in a cloth. He was Al-Khidr, the guide. Musa Alaihis salam greeted him and said: “I am Musa.” He asked: “Musa, the prophet of the children of Israel?” Musa Alaihis salam replied: “Yes, and I have come to you so that I could learn wisdom from you which you have been given.” Khidr said: “Surely, you will not be able to bear with me patiently. I have knowledge from Allah which you do not have, and you have knowledge from Allah which I do not have.” Musa Alaihis salam said: “If Allah so wills, you will find me patient and I shall not disobey you in any matter.” Khidr agreed to his request saying: “Then, if you follow me, ask me not about anything till I myself mention it to you.”
So they both proceeded, walking along the seaside till a ship passed by them. The crew recognized Khidr, and took them on board with no fare. As they were aboard, Khidr took an axe and tore out a plank of the ship. Musa Alaihis salam exclaimed: “What did you do? You made a hole in the ship, so as to drown those in it? You have indeed done a grievous thing. He (Khidr) said: “Did I not tell you, that you would not be able to have patience with me?” Musa alaihis salam said: “Excuse me for what I forgot, and do not make it difficult for me.” Then a sparrow came and sat down on the edge of the ship and dipped its beak in the sea. Khidr said to Musa Alaihis salam: “My knowledge and your knowledge in comparison to the knowledge of Allah are nothing but like that water which the sparrow has taken in its beak from the sea.”
Then they disembarked and started walking, till khidr spotted a boy and killed him. Musa Alaihis salam said: “Have you slain an innocent person who had killed none? Verily, you have done a n evil thing!” Khidr said: “Did I not tell you that you can have no patience with me?” Musa Alaihis salam realized his mistake and said: “If I ask you anything after this, keep me not in your company, you have received full excuse from my side.”
Then they started their journey again and came to the people of a town, they asked them for food, but they refused to entertain them. There they found a wall about to collapse and Khidr set it up straight. Musa Alaihis salam said: “These are the people who refused us food, yet you repaired the wall. If you had wished, surely you could have taken wages for it!” Khidr said: “This is the parting between me and you. I will tell you the interpretation of (those) things over which you were unable to hold patience. ‘As for the ship, it belonged to poor people working in the sea. So I wished to make a defective damage in it, as there was a king after them who seized every ship by force. “And as for the boy, his parents were believers, and we feared lest he should oppress them by rebellion and disbelief. So we intended that their Lord should change him for them for one better in righteousness and near to mercy. “And as for the wall, it belonged to two orphan boys in the town; and there was under it a treasure belonging to them; and their father was a righteous man, and your Lord intended that they should attain their age of full strength and take out their treasure as a mercy from your Lord. And I did it not of my own accord. That is the interpretation of those (things) over which you could not hold patience.”
The Prophet SallAllahu alaihi wasallam said after he had narrated this story: “We wish Musa could have remained patient, so that Allah may have told us more of their story.” (Al-Bukhari)