He was born in 1058 AD (450 Hijri), in "Tus" (Khorasan province of Iran). He is known as "Hujjat-ul-Islam" (The Proof of Islam). He was formally schooled in his early adulthood, studying under al-Juwayni, a prominent theologian located in Nishapur. During this period, the young Imam Ghazali produced various texts on Islamic law and theology, which are still used to this day.
Once his way back from Jurjan to Tus, Imam Ghazzali was robbed by highwaymen. When they left him he followed them but was told: "Leave us or you will die." He replied: "I ask you for Allah sake to only return to me my notes, for they are of no use to you." The robber asked him: "What are those notes?" He said: "Books in that satchel, for the sake of which I left my country in order to hear, write, and obtain their knowledge." The robber laughed and said: "How can you claim that you obtained their knowledge when we took it away from you and left you devoid of knowl-edge!" Then he gave an order and the satchel was returned to him. Imam Ghazzali said: "This mans utterance was divinely inspired: Allah caused him to say this in order to guide me. When I reached Tus I worked for three years until I had memorized all that I had written down."
Imam Ghazzali came to Baghdad in 484 Hijri and began a prestigious career of teaching, giving fatwa, and authoring books in nearly all the Islamic sciences of his day. His skill in refuting opponents was unparalleled except by his superlative godwariness, which led him to abandon his teaching position at the Nizamiyya school four years later, deputizing his brother Ahmad, famous for his preaching, to replace him. Upon completion of pilgrimage to Makkah, Imam Ghazzali headed for Damascus, then al-Qudus, then Damascus again where he remained for several years, taking up the ascetic life with the words: "We sought after knowledge for other than Allahs sake, but He refused that it be for anything other than Him."
Imam Ghazali once said: "The Sufi path consists in cleansing the heart from whatever is other than Allah... I concluded that the Sufis are the seekers in Allah's Way, and their conduct is the best conduct, and their way is the best way, and their manners are the most sanctified. They have cleaned their hearts from other than Allah and they have made them as pathways for rivers to run, carrying knowledge of Allah."
He came out of seclusion in 499 and travelled to Cairo, Iskandariyya and other places, finally returning to Baghdad where he taught his magnum opus Ihya Ulum al-Din until his death in nearby Tus, occupying the remainder of his time with devotions, Quran recitations, prayer and fasting, and the company of Sufis. Ibn al-Jawzi narrated in al-Thabat Inda al-Mamat ("Firmness at the Time of Death") from Imam Ghazzalis brother Ahmad: "On Monday (14 Jumada al-Akhira) at the time of the dawn prayer my brother Abu Hamid (Ghazali) made his ablution, prayed, then said: "Bring me my shroud." He took it, kissed it and put it on his eyes, saying: "We hear and obey in readiness to enter the Kings presence." Then he stretched his legs, facing the Qibla, and died before sunrise." It is related that al-Shadhili saw a dream in which the Holy Prophet pointed out Imam Ghazzali to Musa (Moses) and Isa (Jesus) asking them: "Is there such a wise scholar in your communities?" to which they replied: "No."