The story of Musa (alayhissalam) and Al-Khidr is mentioned in Surah Al-Kahf.
وَإِذْ قَالَ مُوسَىٰ لِفَتَاهُ لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ مَجْمَعَ الْبَحْرَيْنِ أَوْ أَمْضِيَ حُقُبًا
“And (remember) when Musa said to his boy-servant: “I will not give up (travelling) until I reach the junction of the two seas or (until) I spend years and years in travelling.”
فَلَمَّا بَلَغَا مَجْمَعَ بَيْنِهِمَا نَسِيَا حُوتَهُمَا فَاتَّخَذَ سَبِيلَهُ فِي الْبَحْرِ سَرَبًا
But when they reached the junction of the two seas, they forgot their fish, and it took its way through the sea as in a tunnel.
فَلَمَّا جَاوَزَا قَالَ لِفَتَاهُ آتِنَا غَدَاءَنَا لَقَدْ لَقِينَا مِن سَفَرِنَا هَـٰذَا نَصَبًا
So when they had passed further on (beyond that fixed place), Musa said to his boy-servant: “Bring us our morning meal; truly, we have suffered much fatigue in this, our journey.”
قَالَ أَرَأَيْتَ إِذْ أَوَيْنَا إِلَى الصَّخْرَةِ فَإِنِّي نَسِيتُ الْحُوتَ وَمَا أَنسَانِيهُ إِلَّا الشَّيْطَانُ أَنْ أَذْكُرَهُ ۚ وَاتَّخَذَ سَبِيلَهُ فِي الْبَحْرِ عَجَبًا
He said:”Do you remember when we betook ourselves to the rock? I indeed forgot the fish, none but Shaitan (Satan) made me forget to remember it. It took its course into the sea in a strange (way)!”
قَالَ ذَٰلِكَ مَا كُنَّا نَبْغِ ۚ فَارْتَدَّا عَلَىٰ آثَارِهِمَا قَصَصًا
[Musa] said: “That is what we have been seeking.” So they went back retracing their footsteps.
فَوَجَدَا عَبْدًا مِّنْ عِبَادِنَا آتَيْنَاهُ رَحْمَةً مِّنْ عِندِنَا وَعَلَّمْنَاهُ مِن لَّدُنَّا عِلْمًا
Then they found one of Our slaves, unto whom We had bestowed mercy from Us, and whom We had taught knowledge from Us.
قَالَ لَهُ مُوسَىٰ هَلْ أَتَّبِعُكَ عَلَىٰ أَن تُعَلِّمَنِ مِمَّا عُلِّمْتَ رُشْدًا
Musa 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)?”
قَالَ إِنَّكَ لَن تَسْتَطِيعَ مَعِيَ صَبْرًا
He (Khidr) said: “Verily! You will not be able to have patience with me!
وَكَيْفَ تَصْبِرُ عَلَىٰ مَا لَمْ تُحِطْ بِهِ خُبْرًا
“And how can you have patience about a thing which you know not?”
قَالَ سَتَجِدُنِي إِن شَاءَ اللَّـهُ صَابِرًا وَلَا أَعْصِي لَكَ أَمْرًا
Musa said: “If Allah wills, you will find me patient, and I will not disobey you in aught.”
قَالَ فَإِنِ اتَّبَعْتَنِي فَلَا تَسْأَلْنِي عَن شَيْءٍ حَتَّىٰ أُحْدِثَ لَكَ مِنْهُ ذِكْرًا
He (Khidr) said: “Then, if you follow me, ask me not about anything till I myself mention it to you.”
فَانطَلَقَا حَتَّىٰ إِذَا رَكِبَا فِي السَّفِينَةِ خَرَقَهَا ۖ قَالَ أَخَرَقْتَهَا لِتُغْرِقَ أَهْلَهَا لَقَدْ جِئْتَ شَيْئًا إِمْرًا
So they both proceeded, till, when they embarked the ship, he (Khidr) scuttled it. Musa said: “Have you scuttled it in order to drown its people? Verily, you have committed a thing “Imra” (a Munkar – evil, bad, dreadful thing).”
قَالَ أَلَمْ أَقُلْ إِنَّكَ لَن تَسْتَطِيعَ مَعِيَ صَبْرًا
He (Khidr) said: “Did I not tell you, that you would not be able to have patience with me?”
قَالَ لَا تُؤَاخِذْنِي بِمَا نَسِيتُ وَلَا تُرْهِقْنِي مِنْ أَمْرِي عُسْرًا
[Musa] said: “Call me not to account for what I forgot, and be not hard upon me for my affair (with you).”
فَانطَلَقَا حَتَّىٰ إِذَا لَقِيَا غُلَامًا فَقَتَلَهُ قَالَ أَقَتَلْتَ نَفْسًا زَكِيَّةً بِغَيْرِ نَفْسٍ لَّقَدْ جِئْتَ شَيْئًا نُّكْرًا
Then they both proceeded, till they met a boy, he (Khidr) killed him. Musa 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)!”
قَالَ أَلَمْ أَقُل لَّكَ إِنَّكَ لَن تَسْتَطِيعَ مَعِيَ صَبْرًا
(Khidr) said: “Did I not tell you that you can have no patience with me?”
قَالَ إِن سَأَلْتُكَ عَن شَيْءٍ بَعْدَهَا فَلَا تُصَاحِبْنِي ۖ قَدْ بَلَغْتَ مِن لَّدُنِّي عُذْرًا
[Musa] said: “If I ask you anything after this, keep me not in your company, you have received an excuse from me.”
فَانطَلَقَا حَتَّىٰ إِذَا أَتَيَا أَهْلَ قَرْيَةٍ اسْتَطْعَمَا أَهْلَهَا فَأَبَوْا أَن يُضَيِّفُوهُمَا فَوَجَدَا فِيهَا جِدَارًا يُرِيدُ أَن يَنقَضَّ فَأَقَامَهُ ۖ قَالَ لَوْ شِئْتَ لَاتَّخَذْتَ عَلَيْهِ أَجْرًا
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. [Musa] said: 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 Masaakeen (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.”
[Surah Al-Kahf (18): 60-82]
SubhanAllah this story alone has many, many lessons we can draw from it. Here are the lessons derived by Imam As-Saadi (rahimahullah) from this story: http://attafsir.files.wordpress.com/2010/08/sadee_moosaa_khadir_en.pdf
[Please note that there is a dispute as to whether Al-Khidr is a Prophet or not.]