Ubayy b. Ka'b narrated to us that he had heard Allah's Messenger (ﷺ) as saying
Moses had been delivering sermons to his people. And he made this remark: No person upon the earth has better knowledge than I or nothing better than mine. Thereupon Allah revealed to him: I know one who is better than you (in knowledge) or there is a person on the earth having more knowledge than you. Thereupon he said: My Lord, direct me to him. It was said to him: Keep a salted fish as a provision for journey. The place where that fish would be lost (there you will find that man). So he set forth and a young slave along with him until they came to a place Sakhra. but he did not find any clue. So he proceeded on and left that young man there. The fish began to stir in water and the water assumed the form of an ark over the fish. The young man said: I should meet Allah's Apostle (peace be upon him) and inform him, but he was made to forget and when they had gone beyond that place, he (Moses) said to the young man: Bring breakfast. We have been exhausted because of the journey, and he (Moses) was not exhausted until he had crossed that (particular) place (where he had) to meet Khadir, and the youth was reminded and said: Did you not see that as we reached Sakhra I forgot the fish and it is satan alone who has made me forgetful of it'? It is strange that he has been able to find way in the ocean too. He said: This is what we sought for us. They returned retracing their steps, and he (his companion) pointed to him the location (where) the fish (had been lost). Moses began to search him there. He suddenly saw Khadir wrapped in a cloth and lying on his back. He said to him: As-Salamu-'Alaikum. He removed the cloth from his face and said: Wa 'Alaikum-us-Salam! Who are you? He said: I am Moses. He said: Who Moses? He said: Moses Of Bani Isra'il. He said: What brought you here? He said: I have come so that you may teach me what you have been taught of righteousness. He said: You shall have to bear with me, and how can you have patience about a thing of which you have no comprehensive knowledge? You will not have patience when you see me doing a thing I have been ordered to do. He said: If Allah pleases, you will find me patient, nor shall I disobey you in aught. Khadir said: If you follow me, don't ask me about anything until I explain it to you. So they went on until they embarked upon a boat. He (Khadir) made a hole in that. Thereupon he (Moses) said: You have done this so that you may drown the persons sitting in the boat. You have done something grievous. Thereupon he said: Did I not tell you that you will not be able to bear with me? Thereupon he (Moses) said: Blame me not for what I forgot and be not hard upon me for what I did. (Khadir gave him another chance.) So they went on until they reached a place where boys were playing. He went to one of them and caught hold'of one (apparently) at random and killed him. Moses (peace be upon him) felt agitated and said: You have killed an innocent person not guilty of slaying another. You have done something aboininable. Thereupon Allah's Messenger (ﷺ) said: May Allah have mercy upon us and Moses. Had he shown patience he would have seen wonderful things, but fear of blame, with respect to his companion, seized him and he said: If I ask anything after this, keep not company with me. You will then have a valid excuse in my case, and had he (Moses) shown patience he would have seen many wonderful things. He (the narrator) said: Whenever he (the Holy Prophet) made mention of any Prophet, he always said: May there be mercy of Allah upon us and upon my brother so and so. They, however, proceeded on until they came to the inhabitants of a village who were very miserly. They went to the meeting places and asked for hospitality but they refused to show any hospitality to them. They both found in that village a wall which was about to fall. He (Khadir) set it right. Thereupon he (Moses) said: If you so liked. you could get wages for it. Thereupon he said: This is the partince, of ways between me and you, and, taking hold of his cloth, he said: Now I will explain to you the real significance (of all these acts) for which you could not show patience. As for the boat, it belonged to the poor people working on the river and I intended to damage it for there was ahead of them (a king) who seized boats by force. (When he came) to catch hold of it he found it a damaged boat, so he spared it (and later on) it was set right with wood. So far as the boy is concerned, he has been, by very nature, an unbeliever, whereas his parents loved him very much. Had he grown up he would have involved them in wrongdoing and unbelief, so we wished that their Lord should give them in its place one better in purity and close to mercy. And as for the wall it belonged to two orphan boys in the city and there was beneath it a (treasure) belongin to them,... up to the last verse.