Prophet Ibrahim had become over 90 years old and had no child. Sarah, his wife, gave her slave-girl, by name of Hajira, to Ibrahim as a wife. Through Hajira, Almighty God blessed Ibrahim with a son: Ishmael (peace be upon him).
Sarah became jealous of Hajira. Finally, decided to test the patience of Ibrahim by asking him to take Hajira and the infant Ishmael into a desert and leave them there. Ibrahim was guided to that desert area which later became famous as Mecca. Prophet Ibrahim brought Hajira and Ishmael to Mecca and left them as commanded by God.
Whatever provisions Ibrahim had brought for his wife and child finally ran out. The baby Ishmael started crying out of thirst. Hajira set out in search for water. She was standing on the small hill of Safa; she looked towards the hill of Marwah and thought that there was water over there. When she reached Marwah, there was not water; it was just a mirage. She turned facing Safa and thought that there was water over there. She returned to Safa, but there was no water; it was just a mirage.
As mother, desperately looking for water for her child, Hajira ran between the hills of Safa and Marwah seven times. Finally, she saw that a water stream had started at the feet of Ishmael. This miraculous steam is still running on beside the Kaaba, the House of God, and it is known as Zamzam.
God so much loved the spirit of motherhood demonstrated by Hajira - ho ran seven times between the hills of Safa and Marwah in search of water for her child that, He has commanded the Muslim pilgrims to walk between the hills of Safa and Marwah when they go for the pilgrimage.
The ritual of walking between the two hills of Safa and Marwah seven times is an essential part of pilgrimage and it perpetuates the memory of Hajira as a mother.