Later on Ghazzali studied at Nishapur under the celebrated Abu'l-Maali. Here also at the court of the Vizier Nizam-ul-mulk (the school-fellow of Omar Khayyam) he took a distinguished part in those discussions on poetry and philosophy which were so popular in the East. In 1091 Nizam-ul-mulk appointed him to the professorship of Jurisprudence in the Nizamiya College at Bagdad, which he had founded twenty-four years previously. Here Ghazzali lectured to a class of 300 students. In his leisure hours, as he informs us in his brief autobiography, "Al munkidh min uddallal" ("The Deliverance from error") he busied himself with the study of philosophy. He also received a commission from the Caliph to refute the doctrine of the Ismailians.
In the first chapter it has been mentioned how a deep-seated unrest and thirst for peace led him, after many mental struggles, to throw up his appointment and betake himself to religious seclusion at Damascus and Jerusalem. This, together with his pilgrimage to Mecca and Medina, lasted nearly ten years. Ibn Khalliqan informs us that he also went to Egypt and stayed some time in Alexandria. Here the fame of the Almoravide leader in Spain, Yusuf ibn Tashifin, is said to have reached Ghazzali, and to have made him think of journeying thither. This prince had begun those campaigns in Spain against the Cid and other Christian leaders which were destined to add Andalusia to his Moroccan dominions. By these victories in the West he had to some extent retrieved the decline of Islam in the East. It is natural to suppose that the enthusiastic Ghazzali would gladly have met with this champion of Muhammadanism. The news of Yusuf ibn Tashifin's death in 1106 seems to have made him renounce his intention of proceeding to Spain.
The realisation of Ghazzali's wish to withdraw from public affairs and give himself to a contemplative life was now interrupted. The requests of his children and other family affairs, of which we have no exact information, caused him to return home. Besides this, the continued progress of the Ismailians, the spread of irreligious doctrines, and the increasing religious indifference of the masses not only filled Ghazzali and his Sufi friends with profound grief but determined them to stem the evil with the whole force of their philosophy, the ardour of vital conviction, and the authority of noble example.
In addition, the governor of Nishapur, Muhammad Ibn Malikshah, had asked Ghazzali to proceed thither in order to help to bring about a religious revival. Thus, after an absence of ten years, he returned to Nishapur to resume his post as teacher. But his activity at this period was directed to a different aim than that of the former one. Regarding the contrast he speaks like a Muhammadan Thomas á Kempis. Formerly, he says, he taught a knowledge which won him fame and glory, but now he taught a knowledge which brought just the opposite. Inspired with an earnest desire for the spiritual progress of his co-religionists and himself, and convinced that he was called to this task by God, he prays the Almighty to lead and enlighten him, so that he may do the same for others.
How long Ghazzali occupied his professorship at Nishapur the second time is not precisely clear. Only five or six years of his life remained, and towards the close he again resigned his post to give himself up to a life of contemplation to which he felt irresistibly drawn, in his native city of Tus. Here he spent the rest of days in devotional exercises in friendly intercourses with other Sufis and in religious instruction of the young. He died, devout as he lived, in the fifty-fourth year of his age, a.d. 1111. He founded a convent for Sufis and a professorship of jurisprudence.
Ghazzali's activity as an author during his relatively short life was enormous. According to the literary historians, he is the author of ninety-nine different works. These are not all known to us, but there are existing in the West a considerable quantity of them, some in Latin and Hebrew translations, as he was much studied by the Jews in the Middle Ages. A writer in the Jewish Encyclopædia says (sub. voc.), "From his 'Makasid-al-Falasifah' in which he expounded logic, physics and metaphysics according to Aristotle, many a Jewish student of philosophy derived much accurate information. It was not, however, through his attacks on philosophy that Ghazzali's authority was established among Jewish thinkers of the middle ages, but through the ethical teachings in his theological works. He approached the ethical idea of Judaism to such an extent that some supposed him to be actually drifting in that direction."
Although Ghazzali was a Persian, both by race and birthplace, most of his works are composed in Arabic, that language being as familiar to Muhammadan theologians as Latin to those of Europe in the Middle Ages. One of his most important works is the "Tahafut al falasifah," "Destruction of the Philosophers," which the great Averroes endeavoured to refute. Somewhat in the style of Mr. Balfour's "Defence of philosophic doubt," Ghazzali attempts to erect his religious system on a basis of scepticism. He denies causation as thoroughly as Hume, but asserts that the divine mind has ordained that certain phenomena shall always occur in a certain order, and that philosophy without faith is powerless to discover God. Although chiefly famous in the West as a philosopher, he himself would probably have repudiated the title. He tells us that his object in studying philosophy was to confute the philosophers. His true element was not philosophy but religion, with which his whole being was penetrated, and which met all his spiritual needs. Even in his most heterogeneous studies he always kept before him one aim—the confirmation, spread, and glorification of Islam.
It is true that more than one of his contemporaries accused him of hypocrisy, saying that he had an esoteric doctrine for himself and his private circle of friends, and an exoteric for the vulgar. His Sufistic leanings might lend some colour to this accusation, it being a well-known Sufi habit to cloak their teaching under a metaphorical veil, wine representing the love of God, etc., as in Hafiz and Omar Khayyam. Against this must be set the fact that in his autobiography written near the close of his life, he constantly refers to his former works, which he would hardly have done had he been conscious of any striking discrepancy between his earlier and his later teaching. There is no reason to doubt his previously-quoted statement that he "studied philosophy in order to refute the philosophers."
He was, at any rate, intensely indignant at having his orthodoxy impugned, as appears from a striking story narrated by the Arabic historian Abu'l Feda. He tells us that Ghazzali's most important work, "The revival of the religious sciences" had created a great sensation when it reached Cordova. The Muhammadan theologians of Spain were rigidly orthodox, and accused the work of being tainted by heresy. They represented to the Caliph Ali Ibn Yusuf that not only this but all Ghazzali's other works which circulated in Andalusia should be collected and burnt, which was accordingly done. Not long after, a young Berber from North Africa named Ibn Tumart wandered to Bagdad, where he attended Ghazzali's lectures. Ghazzali noticing the foreigner, accosted him, and inquired regarding religious affairs in the West, and how his works had been received there. To his horror he learned that they had been condemned as heretical and committed to the flames by order of the Almoravide Caliph Ali. Upon this, Ghazzali, raising his hands towards heaven, exclaimed in a voice shaken with emotion, "O God, destroy his kingdom as he has destroyed my books, and take all power from him." Ibn Tumart, in sympathy with his teacher, said, "O Imam[44] Ghazzali, pray that thy wish may be accomplished by my means." And so it happened. Ibn Tumart returned to his North African, proclaimed himself a Mahdi, gained a large following among the Berbers, and overthrew Ali and the dynasty of the Almoravides. This story is not entirely beyond doubt, but shows the importance attached by Ghazzali's contemporaries to his influence and teaching.
As an example of Ghazzali's ethical earnestness, we may quote the following from his Ihya-ul-ulum ("Revival of the religious sciences"). He refers to the habit common to all Muhammadans of ejaculating, "We take refuge in God." "By the fear of God," he says, "I do not mean a fear like that of women when their eyes swim and their hearts beat at hearing some eloquent religious discourse, which they quickly forget and turn again to frivolity. There is no real fear at all. He who fears a thing flees from it, and he who hopes for a thing strives for it, and the only fear that will save thee is the fear that forbids sinning against God and instils obedience to Him. Beware of the shallow fear of women and fools, who, when they hear of the terrors of the Lord, say lightly, 'We take refuge in God,' and at the same time continue in the very sins which will destroy them. Satan laughs at such pious ejaculations. They are like a man who should meet a lion in a desert, while there is a fortress at no great distance away, and when he sees the ravenous beast, should stand exclaiming, 'I take refuge in that fortress,' without moving a step towards it. What will such an ejaculation profit him? In the same way, merely ejaculating 'I take refuge in God' will not protect thee from the terrors of His judgment unless thou really take refuge in Him."