Al-Bukhaari narrated in his Saheeh (6/396-397, 3364) that Ibn ‘Abbaas (may Allaah be pleased with him) said:
Ibraaheem brought Haajar and her son Ismaa’eel when she was still breastfeeding him, to a place near the Ka’bah under a tree on the spot of Zamzam, at the highest place in the mosque. During those days there was nobody in Makkah, nor was there any water.
So he left them there and left with them a leather bag containing some dates, and a small water-skin containing some water, and set out homeward. Ismaa’eel’s mother followed him saying, “O Ibraaheem! Where are you going, leaving us in this valley where there is no person whose company we may enjoy, nor is there anything (to enjoy)?”
She repeated that to him many times, but he did not look at her. Then she asked him, “Has Allaah commanded you to do this?”
He said, “Yes.” She said, “Then He will not forsake us,” and went back while Abraham proceeded onwards. When he reached al-Thaniyah where they could not see him, he turned to face the Ka’bah, and raising both hands, invoked Allah saying the following prayer:
“O our Lord! I have made some of my offspring to dwell in an uncultivable valley by Your Sacred House (the Ka‘bah at Makkah) in order, O our Lord, that they may perform As-Salaah (Iqaamat-as-Salaah). So fill some hearts among men with love towards them, and (O Allaah) provide them with fruits so that they may give thanks”
Ismaa’eel’s mother went on breastfeeding Ismaa’eel and drinking from the water (she had). When the water in the water-skin had all been used up, she became thirsty and her child also became thirsty. She started looking at him (i.e. Ismaa’eel) tossing in agony. She left him, for she could not endure looking at him, and found that the mountain of al-Safa was the nearest mountain to her on that land. She stood on it and started looking at the valley keenly so that she might see somebody, but she could not see anybody. Then she descended from al-Safa and when she reached the valley, she tucked up her robe and ran in the valley like a person in distress and trouble, till she crossed the valley and reached al-Marwa where she stood and started looking, expecting to see somebody, but she could not see anybody. She repeated that (running between al-Safa and al-Marwa) seven times.
Ibn ‘Abbaas said: The Prophet (peace and blessings of Allaah be upon him) said,
“This is the (origin of) the people’s saa’i (walking) between them between them (i.e. al-Safa and al-Marwa).” When she reached al-Marwa (for the last time) she heard a voice and she said to herself “Shh!” and listened attentively. She heard the voice again and said, “O, (whoever you may be)! You have made me hear your voice; have you got something to help me?”
Then she saw an angel at the place of Zamzam, digging the earth with his heel (or his wing), until water appeared. She started to make something like a basin around it, using her hand in this way, and started filling her water-skin with water with her hands, and the water was flowing out after she had scooped some of it.
Ibn ‘Abbaas said: The Prophet (peace and blessings of Allaah be upon him) said, “May Allah have mercy on the mother of Ismaa’eel! Had she let Zamzam (flow without trying to control it) (or had she not scooped from that water) (to fill her water-skin), Zamzam would have been a stream flowing on the surface of the earth.” And he said: “The angel said to her, ‘Do not be afraid of being neglected, for this is the House of Allah which will be built by this boy and his father, and Allah never neglects His people’…”
Ibn al-Jawzi said in his book Mutheer al-‘Azm al-Saakin (2/47): “This hadeeth explains the reason why it is called Zamzam, because when the water flowed, Haajar tried to control it (zammat-ha). The linguist Ibn Faaris said: Zamzam comes from the words zamamtu al-naaqah (I reined in the camel)