It is highly crucial to begin this article by the following point which not many people are aware of, but is perhaps one of the most decisive moments in Muslim history: the role played by the medieval Moroccan dynasties of the Almoravids and Almohads. They not only saved Morocco and Muslim al Andalus, but also saved the whole Muslim world from possibly terminal onslaught. Here, we only offer a brief summary of this decisive moment, and then, under the final heading we will say more. And whilst we will be able to inform, hopefully enough on this Moroccan role, we won’t be able to go into the whole picture, for this demands a great deal of space, perhaps even a whole book, and this, of course, is not the right venue.
Figure 1. Medina of Marrakesh (Source)
So, briefly here, we remind how when the great Muslim ruler, ibn Abi Amir (Al-Mansur), who had made al Andalus the great power of his time, and who had conducted 52 military operations to stem the Christian reconquest of al Andalus died (in 1002), the situation in al Andalus changed dramatically for the worse. At his death, he was succeeded by his son who ruled for six years before the Peninsula entered a period of chaos. As civil war erupted throughout the territory, Cordoba was burned down in 1018. Muslim Spain, soon, disintegrated into the era of the ‘Party Kings' (reyes de taifas, muluk at-tawa'if) (1009-1091), with thirty more or less independent rulers. Intrigues and civil war soon invited northern Christian invasions. The first great Christian success was the capture of the stronghold of Barbastro, in 1064. Then there followed the even greater success: the capture of Toledo in 1085. Now, the whole of Muslim Spain was under threat. Delegated by the other Reyes, al-Mu’tamid of Seville took ship to North Africa and persuaded Yusuf ibn-Tashfin, the chief of the Moroccan Berber Almoravids, to intervene and save al-Andalus. Yusuf, as we will recount further down, embarked for the Peninsula, and crushed the Christian armies at Zalakah (Sagrajas) (near Badajoz) (in 1086). This victory saved Muslim Spain, and did even more. Indeed, thanks to his timely arrival and military victories, Ibn Tashfin (d. 1106), later emulated by the other great hero of Muslim Spain, the Almohad, Abu Yusuf Ya’qub al-Mansur (d. 1198), al-Andalus was kept under Muslim rule for another century and half. These victories by Ibn Tashfin and Abu Yusuf saved not just Muslim Spain but also North Africa and the whole Muslim world. Indeed, had al-Andalus fallen in the 1080s or sometime in the 12th century (rather than in the mid 13th century (as it subsequently did), Christian forces would have advanced through North Africa, then would have joined the crusaders in the East, and this could have meant the end of the Muslim world. Instead, the victories by Yusuf ibn Tashfin and Abu Yusuf Ya’qub al Mansur delayed the Christian invaders by nearly two centuries, and hence prevented the armies of the Christian Reconquista from joining with the Crusaders. This delay also allowed the Mamluks to come forth (after 1250). Under the mighty ruler, Baybars (d.1277), the Mamluks were able to crush both Crusaders and Mongols (see entries on Damascus, Baghdad, Aleppo, Hama…) When al Andalus finally fell to the Christians (especially after the capture of the Almohad capital, Seville, in 1248,) although the Muslims lost al Andalus (with the exception of Grenada) Mamluk power in the East, and soon the rise of the Ottomans prevented the total collapse of the Muslim world.
We will not be able to look at all this in this particular essay, but at the end of it, we will say more on the Marrakesh based Almoravids and their ultimate role.
Figure 2-3: Two examples of the Almohad architecture: the Giralda in Seville and the Kutubiya in Marrakech. (Source)
The Story of Marrakesh
Marrakesh was founded about 1070 by the Almoravids. The city became the capital of the empire in the Sahara as well as the Maghrib. It was strategically placed on the plain of the Tensift River, just within the arc of the Atlas at the convergence of two major routes across the mountains. In 1147 Marrakesh fell to the Almohads of the High Atlas, who made it the capital of their own. Even when residing in Seville, the city was the centre of the Almohad community with its scholars and military. Marrakesh became by desire of its rulers the centre of attraction for Maghribi scholars and even a certain number from Spain. It was, thus, in Marrakesh that Ibn Rushd in 1153 became engaged in astronomical observations. In 1163 he became associated with the Almohad court; the philosopher Ibn Tufayl (1105-1185) introducing him to the Almohad ruler, Abu Ya’qub, who has greatly interested in philosophy. Ibn Tufayl recommended Ibn Rushd for this task.
The Almoravids, the founders of Marrakesh, known as the veiled men of the Sahara were originally ‘heathen.’ The passage of Muslim traders across the desert brought them knowledge of Islam, and some of the nomads were fascinated by it. The dignity of a formal religion, with ritual and the Book delighted ‘a people whose forebears had known only the haphazardry of idol and fetish worship.’ Following pilgrimage to Makkah in 1045, Yahia ibn Ibrahim, a chief of the Sinhajah Berber tribe, realised the state of religious ignorance in which his fellow-Berbers lived. He met at Al-Qayrawan Abu Imran al-Fasi, a Malikite professor of Law, and requested him to provide a religious teacher to preach Islam among the tribesmen. He finally arranged, though not without difficulty, that a man of religion from southern Morocco, 'Abd Allah b. Yasin, should accompany him on his return to teach his people what they did not know. Abd Allah ibn Yasin had been trained in the schools of Cordova and Seville, and was a man of much ability, who taught seventy sheiks. By great effort, as detailed by Ibn-Khaldun, he taught them the Qur’an and the practices of religion. The teacher with a few of his devoted pupils retired to live apart from the world. The setting chosen for their hermitage was an island on a river beyond the desert, which could have been the Senegal, or the Upper Niger. Their hermitage-colony, or “ribat,” gave the Almoravids their name. Almoravids is a Spanish distortion of the words, al-Morabetin, meaning “The People of the Ribat.” The word “marabout,” a holy man, so widely used in Africa derives also from “ribat.”
Under the leadership of Abd-Allah ibn Yasin, the Almoravids, like the Arabs before them, were inspired, ‘by the freshness of their conversion to Islam, to become great conquerors.’ Once they secured the trading routes, the Almoravids advanced into southern and western Morocco, taking Aghmat in 1057-8. After conquering the Saharan regions of Morocco, they crossed the High Atlas during the summer of 450/1058, under the command of one of their great chiefs, Abu Bakr ibn ‘Umar al-Lamtuni. As the village of Aghmat became too small for the expanding dynasty, a new settlement was founded to the north of the High Atlas. This was Marrakesh (Marrakush).
In the conquest of Morocco, Abu Bakr ibn Umar had as a right hand commander of exceptional qualities: Ibn Tashfin. The latter’s sense of military strategy was first class. As a prelude to future operations, he stormed the cities of Tangier and Ceuta, repaired or rebuilt their fortifications, constructed within their walls great magazines and arsenals, and garrisoned them with large bodies of veterans ‘of tried courage and fidelity.’
Whilst the news of a rebellion in the south drew there Abu Bakr ibn Umar, Yusuf ibn Tashfin, in the meantime, in the north, began a long campaign against the Zenata Berbers in or around 1063, capturing Fez in 1070. He established himself at Marrakech, transforming the city from a campground to a walled capital. From this stronghold he moved east, taking Tlemcen (Tilimsan) (modern Algeria, and gradually extended his power to beyond Algiers, refraining from attacking the natural fortress of the mountain of the Kabyles. When Abu Bakr ibn ‘Umar was killed in the campaign in the south, Yusuf became the overall leader of the movement. Thanks to his able military force, skills, and personal bravery, he was able to extend Almoravid dominions, which soon reached from the eastern boundary of Tunis to the Atlantic, from the Mediterranean to the Senegal. No African ruler had ever before wielded such enormous power. He had by now subdued Meknes, Fes, Tangiers, Ceuta, Algiers, and Tunis—in fact, all the Berber portion of Africa between the Senegal River and Ancient Carthage. In area and population, this territory greatly surpassed any previous other. Thus came forth a great leader.
Ibn Tasfin, Arab writers say, was of medium height and build. He had a clear brown complexion and he had a thin beard. His voice was soft, his speech elegant. His eyes were black, his nose hooked, and he had fat on the fleshy portions of his ears. His hair was curly and his eyebrows met above his nose. He had studied with Ibn Yasin for some twenty years. He was courageous, diligent in holy war, and austere in his tastes. He dressed in wool and covered his face with a veil according to the custom of the desert tribesmen. He ate barley and camel meat and drank milk. ‘He was just and merciful. He was schooled in Sharia law.’
The years of Yusuf prolonged far beyond the ordinary term of human existence, included a full century, three ordinary generations of man. His active life, his abstemious habits, his freedom from those vices which waste the body and enfeeble the mind, enabled him to retain to the last the enjoyment of all his faculties. Although pitiless in the treatment of his enemies, it is related of him that during his entire reign, through motives of mistaken humanity, he never signed the death-sentence of a single criminal. Small indulgence was shown to the two tributary sects which, under the law of Islam, were permitted the exercise of their worship." 
This magnanimity was subsequently shown to his vanquished Spanish princes such as Abd Allah of Grenada, his brother Temim, and al-Mu’tamid of Seville, even when they had fought against him, Yusuf only exiled them to Morocco rather than ordering their execution. This was the man, when following the Christian capture of Toledo in 1085, and the threat to their principalities, the distressed Muslims of Andalusia came to ask to save them from King Alfonso VI of Castile. We will look at this further down. Let’s first look at the beginnings and Yusuf’s foundation of Marrakesh.
Figure 4. Djemaa el-Fna (Source)
Marrakesh: Its Foundation and Dominance
When Ibn-Tashfin built Marrakech he had no idea at all of its potentialities. Its swift growth was amazing. His immediate successor saw a Marrakech with a population of nearly a million ‘a hundred thousand hearth fires’ in the old-fashioned phrase.
The original walled camp which Ibn-Tashfin established was near where the Kutubia (Kutubya) now stands. “When the ramparts were being raised Yusuf-ibn-Tashfin pulled back his sleeves and set about making mortar and placing the rubble and rough stones along with the workmen, acting thus,” says the Arab chronicler, “so as to show his humility before All-High-God.”
Marrakech in the rapidity of its growth from a camp to one of the largest cities in the medieval world lived up to its name, which was in the Berber language the equivalent of “Go quickly!”—or as we might say “Step lively!” The reason for it was that the site of Marrakech had been a place where caravans often were attacked and across which it was the habit for travellers to urge one another to speed their pace. It was a brisk name for a new town. Europe in later years deformed it into Morocco (Marocco in old English; Maroc, French, etc.) and took to calling the whole country by that name.
Marrakech delighted the men of old. Its setting astounded them: a glowing red city, fringed with palms and backed by the dazzling wall of the snowy Atlas Mountains. That snow was ‘a cocktail to the eye of hot and tired travellers, a thrill to parched caravans.’
The city itself was full of beauties and luxuries new to the North African scene. The Kutubia was the skyscraper of old Morocco. From its tower “men of the tallest stature on the ground below looked like little children, and you could see the country for fifty miles round about.” Strangers craned their necks to see the celebrated three golden balls which surmounted the tower. These balls were allegedly made from a royal lady’s boiled-down jewellery. They were so large that the mosque door below had to be removed in order to pass through. They were not solid gold, let it be admitted, but it was stated that the gilding of the foundation base metal cost one hundred thousand Dinars (three hundred thousand United States dollars at late 1940s value). The tower was partially coated with an ornamentation of exquisite beauty: turquoise blue tiles. At its base were the stalls of two hundred merchants of Muslim manuscripts which gave the Kutubia its name. The Mosque of the Book Sellers would indicate a remarkable local interest in literature. The love of books was as strong in the Maghrib as in the Machrek, and Marrakesh was famed for its books, manuscripts, libraries and book shops. The Kutubia with its hundred or so librarians gathered in the shade of the minaret, and the many intermediaries who rushed between places searching for rare and new manuscripts to copy; and also the dallals who bought and sold ancient works from and to the scholars of the city. The sultans themselves collected both works and their authors, whom they wanted to have very close to them.
One visitor asks:
How many towns have two hundred stores selling only books? The marvels of Marrakech were the gossip of Africa. Folk talked of its guesthouse so thronged with distinguished travellers from far lands that a medieval poet says it sheltered “the world of all the Seven Climates… I did not know that such a reunion would be seen until the Day of Resurrection.”
During the reign of Yusuf and the early years of that of his successor, public order was maintained; the trade routes were secure; and the Castilians were so effectually kept in awe that they did not venture to make raids into Andalusia. Neither, at first, did the government raise illegal taxes, and that fact, coupled with general tranquillity, secured public welfare. A high level of prosperity, indeed, was attained: bread was cheap, and vegetables could be obtained for next to nothing. The provinces of Al-Maghrib, as well as those of Spain, had been seriously affected by wars and revolutions; their cities had been repeatedly plundered; their agricultural population had been greatly reduced by enslavement and starvation Yet, at his death, Yusuf left to his successor about 60,000 seers, the equivalent of 120,000 pounds of gold. The Ulama had a great influence in the court whilst on the other hand the free thinkers who had been patronised by the petty rulers were discouraged by the Almoravids. Thus, despite the discontent of some such as the poets who thrived in the courts of the princes, the people as a whole were not dissatisfied.
Ibn-Tashfin governed his people for forty-five years, and lived ninety-seven years, from 1009 to 1106. He lived a temperate hardy life, and the popular songs of Algeria still exalt his fame. His dominions embraced an area ten times greater than that of the Western Caliphate during the era of its greatest prosperity. Every Friday his name was repeated, ‘for the homage and the prayers of the devout, from the pulpits of three hundred thousand mosques.’
According to Ibn al-Athir:
The Emir of the Muslims, Yusuf Ibn Tashfin, was virtuous in his conduct, upright and just; he liked learned and pious men, treated them with honour and appointed them to act as magistrates in his states; he always let himself be guided by their counsels. In acts of clemency and the forgiveness of offences he took great pleasure." 
At his death, Yusuf left his dominions to his son Ali. Ali’s rule was a disaster, which eventually led to the collapse of the Almoravid dynasty and its replacement by that of the Almohads. The Almohads would make of Seville in al Andalus their capital. Marrakesh still played a leading role, and here we can mention one great Almohad accomplishment in the city, its legendary hospital, also called the Bimaristan of Amir al-Muminin al-Mansur Abu Yusuf. Al-Mansur ruled Morocco from 1184 until his death in 1199.
We are told that:
Abu Yusuf ordered the masons and the builders to carry out his plans with the greatest perfection possible. He decorated the hospital with inscriptions and designs of surpassing beauty.... He ordered that flowers should be planted and cultivated in the courtyard, as well as fruit trees, and to have flowing water conducted to all the wards and rooms. He ordered the hospital to be equipped with furniture and to be covered with tapestries of wool, linen and silk, which gave an indescribable richness. He endowed it with ample waqfs and donations, providing the hospital with a daily sum of forty dinars for its expenses."