In Islamic tradition, Ibrahim was commanded by Allah to leave his wife Hagar and their infant son alone in the desert, with only basic provisions, to test their faith. The place was between Al-Safa and Al-Marwah. When their provisions were exhausted, Hagar went in search of help or water. To make her search easier and faster, she went alone, leaving the infant Ishmael on the ground. She first climbed the nearest hill, Al-Safa, to look over the surrounding area. When she saw nothing, she then went to the other hill, Al-Marwah, to look around. While Hagar was on either hillside, she was able to see Ishmael and know he was safe. However, when she was in the valley between the hills she was unable to see her son. Thus Hagar would run while in the valley between the hills and walk at a normal pace while on the hillsides.
Hagar travelled back and forth between the hills seven times in the scorching heat before she returned to Ishmael. When she arrived, she found that a spring had sprouted forth from the crying baby kicking at the sand with his feet. This spring is now known as the Zamzam Well. This Zamzam Well was granted from the angels of Allah to reward Hagar.
The Masjid al Haram houses the holy Kaaba, the focal point of prayer for all Muslims. Safa — from which the ritual walking (sa`i, Arabic: سعى) begins — is located approximately half a mile from the Kaaba. Marwah is located about 100 yards from the Kaaba. The distance between Safa and Marwah is approximately 450 meters, so that seven trips amount to roughly 3.15 kilometers. The two points and the path between them are now inside a long gallery that forms part of the Masjid.
Performing the Sa'i, also known as Sa'ee, serves to commemorate Hajar's search for water and God's mercy in answering prayers.
Dr. Ali Shariati in his book, HAJJ: Reflection on Its Rituals describes the Sa'i:
Sa'i is a search. It is a movement with an aim. It is depicted by running and hurrying. During tawaf (circumambulation) you acted as Hajar. In Ibrahim's position you acted as Ibrahim and Ismail. Once you begin "trying" (Sa'i) you are acting as Hajar again.
Here is a true demonstration of oneness. Shapes, patterns, colors, degrees, personalities, borders, distinctions and distances are destroyed. Naked man and stripped humanity are on the scene! Nothing but faith, belief and action are eminent! Here nobody is spoken of; even Ibrahim, Ismail and Hajar are only names, words and symbols. Whatever exists is moving constantly, humanity and spirituality and between them only discipline. Furthermore, this is Hajj, a decision for an eternal movement in a certain direction. It is also how the whole world moves.
Al-Safa and Al-Marwah are also mentioned in the holy Qur'an. "Behold! Safa and Marwa are among the Symbols of Allah. So if those who visit the House in the Season or at other times, should compass them round, it is no sin in them. And if any one obeyeth his own impulse to good,- be sure that Allah is He Who recogniseth and knoweth." Surah #2 Ayat # 158