Once when Prophet Moses was addressing Banu Israel (children of Israel), he was asked: “Who is the most learned man among the people?”
He said: “I am the most learned.”
Allah admonished Moses as he did not attribute absolute knowledge to Him (Allah SWT). So Allah instructed him to go to the junction of the two seas where he would meet one who was more learned than Moses.
The Quran states: And (remember) when Moses said to his boy-servant: “I will not give up (traveling) until I reach the junction of the two seas or (until) I spend years and years in traveling.” (Quran, Surah Al-Kahf:60)
That learned man at the junction of the two seas was Al-Khidr. When Moses met him and introduced himself, Al-Khidr asked:
“The Moses of Banu Israel?”Moses replied in the affirmative.
The Quran then explains further:
Moosa said to him (Khidr) “May I follow you so that you teach me something of that knowledge (guidance and true path) which you have been taught (by Allah)?” (Quran, Surah Kahf:66)
Al-Khidr replied:
“Verily! You will not be able to remain patient with me, O Moses! I have some of the knowledge of Allah which He has taught me and which you do not know, while you have some knowledge which Allah has taught you which I do not know.”
The Quran states:(67) He (Khidr) said: “Verily! You will not be able to have patience with me!
(68) “And how can you have patience about a thing which you know not?”
Moses assured him that he would be patient and not disobey him in any matter.
69- Moses said, "If God wishes, you will find me patient and I shall not disobey any of your orders."
70-He said to Moses, "If you will follow me, do not ask me about anything until I tell you the story about it."
Both of them set out walking along the seashore. Soon a boat passed by and they requested the crew to take them on board. The crew recognized Al-Khidr and took them on board without fare.
Then a sparrow came and stood on the edge of the boat and dipped its beak once or twice in the sea. Al-Khidr said:
“O Moses! My knowledge and your knowledge have not decreased Allah’s knowledge except as much as this sparrow has decreased the water of the sea with its beak.”
Al-Khidr then removed one of the planks of the boat. Moses said:
“These people gave us a free lift but you have broken their boat and scuttled it so as to drown its people.”
71-They started their journey and some time latter they embarked in a boat in which he made a hole. Moses asked him, "Did you make the hole to drown the people on board? This is certainly very strange".
Al-Khidr replied:72- He said, "Did I not tell you that you would not be able to remain patient with me?"
Moses said (as stated in the Quran): Moosa said: “Call me not to account for what I forgot, and be not hard upon me for my affair (with you).” (Quran, Surah Al-Kahf:73)
They proceeded further and found a boy playing with other boys. Al-Khidr killed him. The Quran describes that in this verse:
Then they both proceeded, till they met a boy, he (Khidr) killed him. (Prophet Moosa) said: “Have you killed an innocent person who had killed none? Verily, you have committed a thing “Nukra” (a great Munkar – prohibited, evil, dreadful thing)!” (Quran, Surah Al-Kahf:74)
AI-Khidr replied:75-“Did I not tell you that you cannot remain patient with me?”
76-Moses said, "If I ask you such questions again, abandon me; you will have enough reason to do so."
They went farther till they came to a town. They asked the people for food, but they refused. In this town they found a wall which was on the point of collapsing. Al-Khidr repaired it with his own hands. Moses said:
“If you had wished, surely you could have taken wages for it.”
The Quran states this as:“Then they both proceeded, till, when they came to the people of a town, they asked them for food, but they refused to entertain them. Then they found therein a wall about to collapse and he (Khidr) set it up straight. (Moosa (Moses)) said: If you had wished, surely, you could have taken wages for it!” (Quran, Surah Kahf:77)
Al-Khidr then replied:
He replied, "This is where we should depart from one another. I shall give an explanation to you for all that I have done for which you could not remain patient.
Al-Khidr then explained all his actions which had astonished Moses and made him question them. He said that the ship which he had damaged, belonged to a few poor people working in the sea. A king was behind them seizing every ship by force. So by making it defective, he had saved it for its owners.
79-As for the ship, it belonged to Masakin (poor people) working in the sea.The king had imposed a certain amount of tax on every undamaged boat. I damaged it so that they would not have to pay the tax.
As for the boy, his parents were believers, and there was a fear that the boy would oppress them by his rebellion and disbelief. So Allah planned to take him away and give them another child instead who would be more righteous and kind.
80-The young boy had very faithful parents. We were afraid that out of love for him they would lose their faith in God and commit rebellion
81-So We decided that their Lord should replace him by a better and more virtuous son.
As for the wall, it belonged to two orphan boys in the town. A treasure was hidden under it which also belonged to them; their father had been a righteous man, and Allah intended to safeguard their treasure. Building the wall ensured that the treasure would be protected till they reached maturity. Al-Khidr concluded that he had not done anything of his own accord but had followed Allah’s instructions.
82-The tumbling wall belonged to two orphans in the town whose father was a righteous person. Underneath the wall there was a treasure that belonged to them. Your Lord wanted the orphans to find the treasure through the mercy of your Lord when they mature. I did not repair the wall out of my own desire. These were the explanations of my deeds about which you could not remain patient."
In spite of repeated reminders from Khidr, and assurances from Moses that he would be patient and not question any of Khidr’s actions, Moses forgot his promise and demanded immediate explanations for actions that seemed to him unjust and inexplicable at the moment.
A number of people have wondered whether khidr was an angel, a Messenger, a Prophet or a wali (“saint”). Sheikh Muhammed Salih Al-Munajjid (islamqa.info) describes it as follows: “From the general meaning of the Quranic verses it appears that he was a prophet.”
Shaykh al-Shanqeeti (may Allah have mercy on him) said in his commentary on the verse (interpretation of the meaning):
“Then they found one of Our slaves, on whom We had bestowed mercy from Us, and whom We had taught knowledge from Us” (Surah Al-Kahf 18:65)