Prophet Ismail (a.s) was the son of Ibrahim (a.s) and Hajar. One day Ibrahim (a.s) took his baby son and wife (Hajar) to the site where Ka'ba can be found today. He gave them some dates and water and started to leave. As Ibrahim (a.s) walked away, Hajar followed and asked why they were being left in this empty place. She understood from his silence that Allah had commanded him to do this. Finally, she asked if Allah had ordered him to do this and he replied that it was so. Upon hearing this, she accepted Allah's will and returned to the place where Ibrahim (a.s) had left her.
As soon as Ibrahim (a.s) was out of sight, he turned and prayed to Allah to protect and provide for his family which he had left out in the wilderness:
رَّبَّنَآ إِنَّيۤ أَسْكَنتُ مِن ذُرِّيَّتِي بِوَادٍ غَيْرِ ذِي زَرْعٍ عِندَ بَيْتِكَ ٱلْمُحَرَّمِ رَبَّنَا لِيُقِيمُواْ ٱلصَّلاَةَ فَٱجْعَلْ أَفْئِدَةً مِّنَ ٱلنَّاسِ تَهْوِيۤ إِلَيْهِمْ وَٱرْزُقْهُمْ مِّنَ ٱلثَّمَرَاتِ لَعَلَّهُمْ يَشْكُرُونَ
"O our Lord! I have made some of my offspring to dwell in a valley without cultivation, by Thy Sacred House; In order, O our Lord that they may establish regular prayer; So fill the hearts of some among men with love towards them, and feed them with fruits; So that they may give thanks." (al-Qur'an 14:37)
Ismail (a.s) and his mother lived for some time on the water and dates Ibrahim (a.s) left them, but finally the water ran out, and Ismail's (a.s) mother could no longer produce enough milk to feed Ismail (a.s). The mother could not bear to see her child suffering, so she ran to the top of nearby Mount Safa to see if she could find someone to help her. When she could see no one, she ran down the mountain and across the valley to Mount Marwa. She ran from one mountain to the other seven times, looking for water or help. After the seventh time she heard a voice and she called out to it for help. When she looked she saw an angel digging the earth with his heel until water flowed forth. That place was the site of Zam-zam. She carefully made a barrier around the place where the water was flowing, and filled her waterbag with her hands. Then she was able to drink water and feed her baby. The angel also told her not to be afraid, that she and her son would be provided for.
Ismail (a.s) and his mother continued to live at this place all by themselves for some time. One day some people of the Jurhum tribe were passing through the valley. They didn't intend to stop, because they knew that there had never been any water in that valley. But they saw a kind of bird which was known to frequent wet spots, so they followed it to the spring of Zam-zam. There they found Ismail's (a.s) mother sitting by the water.
Ismail's mother agreed they could settle there for a while, as long as they did not claim possession to the water. Some of the people of the tribe settled by the water permanently and Ismail grew up amongst them.