The Roman conquests
The Roman influence will be preserved in the south until 285 AD. As of the end of 4th century AD, under the reign of the Roman emperor Diocletian, the Romans maintained nothing but one thin presence on the coast, around Tangier. They remained in the north until 429 AD; date of the passage of the Vandals in this part of Mauretania Tingitana. In 533 AD, the Byzantine fleets and then the Visigoths occupied Ceuta and Essaouira.
Umayyad conquest of North Africa
It was at this point that Arab military expeditions into North Africa were first launched by local initiative from Egypt, continuing for years and resulting in the spread of Islam.
In 644 at Madinah, Caliph Umar (Omar) was succeeded by Uthman ibn Affan (Othman), during whose twelve-year rule Armenia, Cyprus, and all of Iran, would be added to the growing Islamic empire; Afghanistan and North Africa would receive major invasions; and Muslim sea raids would range from Rhodes to the southern coasts of the Iberian Peninsula. The Byzantine navy would be defeated in the eastern Mediterranean.
It was about 642 during the reign of the second Khalifa, Omar b. al-Khattab, when Amr b. al-‘As, at the head of a large Muslim army, took the initiative of entering Egypt, then under the Byzantine empire. His capture of Alexandria, the capital of the Byzantine empire, in the same year, brought an end to the Byzantine rule in Egypt and a lot of relief to its Christian subjects, especially the Copts who bore the greater brunt of the Byzantine oppression. By 642 when ‘Amr was recalled to Madina, he had already conquered Cyrenaica and Tripolitania further to the west. During the same period, Uqba b. Nafi’ al-Fihri, then a commander under ‘Amr, penetrated as far south as the oasis of Zawila. This started the process of Islamisation of the North African region as far as the Maghreb, a complex process which took over two centuries to come to fruition. Sidna Uqbah b. Nafi’, the head of the Muslim army in the Maghreb had already shown the way by leading his forces along these routes as far as Kawar which bordered Kanem in 666. When in 718 the Umayyad Caliph Omar b. Abdellaziz appointed Isma’il b. Ubayd Allah, a learned scholar of Hadith, as Amir of lfriqiya (current Tunisia), he sent with him ten scholars to teach spread Islam. This policy of the Caliph was to set the standard. Thus Abderrahman b. Habib b. Abi Ubayda b. Uqbah b. Nafi’, who was appointed the governor of Ifriqiya in 127/745 ordered wells to be dug along the trans-Saharan trade route from Sijilmasa (current Errachidia) in the Morocco to Awdaghust in Ghana. This was certainly to increase not only the volume of trade but also the “volume” of da’awah in the region.
What ever may be the gains of Uqba, he himself did not have the opportunity to consolidate it as he died in the battle of Tohuda with the Berbers in 683. His deputy Zuhair b. Qays, who took over from him did not find it easy either. He too died in a battle about five years later in 688/689 in an attack on the Byzantine forces that had occupied Cyrenaica during his operations in Tunisia. It was Musa b. Nusayr about twenty years after Uqba that was able to consolidate the gains of his predecessors, pacified a good part of Ifriqiya, the Sus, Dar’a and Tafilalit, and began a more systematic propagation of Islam. Musa b. Nusayr’s deputy the Moroccan Berber Tariq b. Ziyyad (d. 720) had led the Muslim armythe Visigothic Kingdom (comprising modern Spain and Portugal) and captured what became al-Andalus in 716. Tariq ibn Ziyad is considered to be one of the most important military commanders in Islamic history. He was initially the deputy of Musa ibn Nusair in North Africa, and was sent by his superior to launch the first thrust of a conquest of the Visigothic Kingdom (comprising modern Spain and Portugal). On April 29, 711, the armies of Tariq ibn Ziyad, in command of an army of 10,000 men, landed at Gibraltar (the name Gibraltar is derived from the Arabic name Jabal al Tariq, which means mountain of (the) Tariq, or the more obvious Gibr Tariq, meaning rock of Tariq).
The Muslim armies swept through al-Andalus and, in the summer of 711, won a decisive victory when the Visigothic king, Roderic, was defeated and killed on July 19 at the Battle of Guadalete. Wasting no time to relish his victory, Tarik pushed on with his dashing and seemingly tireless Moorish cavalry to the Spanish city of Toledo. Within a month’s time, General Tarik ibn Ziyad had effectively terminated European dominance of the Iberian peninsula. Musa ibn Nusayr joined Tarik in Spain and helped complete the conquest of Iberia with an army of 18,000 men. The two commanders met in Talavera, where the Moors were given the task of subduing the northwest of Spain. With vigor and speed they set about their mission, and within three months they had swept the entire territory north of the Ebro River as far as the Pyrenees Mountains and annexed the turbulent Basque country. Tariq did however not rest with the conquest of Iberia. In 722, Moroccan forces crossed the Pyrenees and opened Gothic Gaul (France), seizing several towns in the south of that country. The Goths in Aquitaine, under their leader Eudes, were defeated at Garonne, and they were forced back into central France, carrying with them news of the might Muslim army. Ten years later, in 732, Muslim forces launched what was to be their final bid to overcome all of Western Europe when a massive army under the command of the Umawid governor of Spain, Emir Abderrahman, began laying waste to large parts of Frankish and Gothic France. The Frankish king at the time was Charles Martel immediately mobilized a counter attack. The armies of Charles Martel and Abderrahman met in battle between the towns of Tours and Potiers in Central France in October 732. Accounts have it that 375,000 Muslims were martyred – France was utterly victorious over the Muslim opening of Europe was halted in its tracks. Afterwards, Tariq was made governor of al-Andalus but eventually was called back to Damascus by the Umayyad Caliph Al-Walid I, where he spent the rest of his life.
The Foundation of the Moroccan State: The Idrissid Caliphate
When Moulay Idriss showed up in Morocco, soon, all the major Berber tribes had pledged allegiance to him. However, a lot of Morocco was still non-Muslim. When Moulay Idriss has moved to the nearby valley of Zerhoun, where he founded his capital that is now called after his name, the Imam assembled an army to combat the local rebel Berber tribes who were mostly Jewish and Christian. They were soon defeated and most of them converted to Islam. He took rest for a time and then headed out to conquer more of the surrounding tribes. They either became Muslim or were taken prisoner and some were killed. The battles stopped in 758 when Moulay Idriss made a visit to Tlemcen. The people there pledged al-bay’ah to him and a mosque was built. His name was carved into the pulpit there. Soon after, the whole Berber tribes fell under his cause. Tilimsan is to become the new capital of Idrissid Morocco before the Imam’s foundation of the great city of Fez in 789.
It soon reached the Abbasid Sultan Harun ar-Rachid that the Imam’s influence and popularity were spreading east. As can be perceived from the Imam’s sermons, it was his plan to conquer the whole of the African continent. Harun ar-Rachid sent a cunning assassin named Shumakh ibn Sulayman to assassin him. He had promised him great wealth if he could carry out this task. Shumakh was sent to Ibrahim b. al-Aghlab in Tunisia where he was allowed protected passage into Morocco. Shumakh entered the court of Imam Idriss acting as if he had fled from Arabia. Any Arab that came fleeing from the Abbasids was protected and honoured by Moulay Idriss at the time. The Imam found Shumakh to be well educated and eloquent. Shumakh would compose magnificent poetry in praise of the Ahl al-Bayt whilst calling the Berbers to Moulay Idriss’ cause. The Imam was so impressed with him that he made him one of his closest men. However, his freedman Raachid al-Awarbi did not trust Shumakh. He was very careful not to leave Shumakh alone with the Imam.
One day Raachid was held up somewhere. Shumakh took his opportunity. He presented the Imam with a gift of perfume. “This is a bottle of the finest perfume that I have with me, but I see that you are more deserving of it than I do.” Moulay Idriss thanked him and opened the bottle. He took one sniff and he fell to the ground. It was a deadly poison. Shumakh moved quickly to the stables and took his horse that he had been preparing for his escape. He mounted him and rushed back east. When Raachid came back, he found his master on the floor. He bent down and placed the Imam’s head on his lap. Moulay Idriss was opening his mouth to tell him something, but he could not speak. He stayed in this state until the afternoon and finally passed away. Raachid soon heard of Shumakh’s presence on the road east. Raachid set out to catch him with a band of Berbers. He soon caught up with him and was able to injure him, but Shumakh managed to escape and reach Baghdad. It was said he returned to Baghdad with one of his hands paralysed.
Imam Moulay Idriss died in 762; he left behind his Berber wife, Lalla Kanza bint Uqba al-Awrabi, 7 months pregnant with his heir. The child was born three months after Moulay Idriss’ death. However, Raachid had been killed two years before Moulay Idriss was issued a Caliph. Berbers who had been paid off by Ibrahim al-Aghlab, the ruler of Tunisia (Ifriqya) at the time, killed him. They carried his head to Tunisia. Harun Rachid had appointed Ibrahim al-Aghlab over Tunisia in 800. Moulay Idriss II (said “al-Azhar”, the blossomed) was born in 791 or 792. Raachid took him under his wing. He memorized the Quran by the age of eight. Raachid then taught him the sciences of Hadith, Islamic law, language, poetry, literature, horse riding, archery and other forms of the art of war. At the age of 11, he was ready to take up the responsibility of Imamate. The Berbers pledged al-bay’ah to him in 804/805. The Imam addressed the people with a powerful speech calling them to God and His obedience. The exclusivity of Ahl al-Bayt’s claim to the Caliphate continued in the admonition of Moulay Idriss al-Azhar when he pledged their allegiance to his Imamate.
In 809, Moulay Idriss al-Azhar re-founded the city of Fez on the left bank of the river Fez. During the next nineteen years of his reign until his death in 829 at the age of 36, the Imam reunified Morocco, re-established its firm allegiance to Islam, and prepared the way for the Arabization of an amorphous and mainly tribal society. Doing so, he brought together in one faith and under one banner the kernel of a Sharifian state. For the next generations, the Idrissid concept of Imamate re-established especially by Moulay Idriss II maintained its hold in the political and spiritual system of Morocco. Although sharifism attained its own glory under the rule of the Imam Moulay Idriss II, the Idrissid dynasty did not stay in power for long (788-974). As a result Morocco entered into chaos and rule of shattered states notably the ones of Barghwata, Maghrawa and Bani Yafran. The age of the Berber dynasties was soon to be launched. The heyday of Moroccan history corresponds to the rule of the three Berber dynasties that succeeded to the throne from the fifth/eleventh to the eighth/fourteenth centuries: the Almoravids (“al-Murabitun”; 1061-1147), the Almohads (“al-Muwahhidun”; 1130-1269), and the Marinids (“al-Mariniyun”; 1244-1398) corresponding to the three major Berber tribes Sanhaja, Masmuda, and Zenata.
Flag of Idrisid dynasty
Moroccan Almoravid Dynasty
The army of Yusuf ibn Tachafin entered the Andalusia on several occasions (1086, 1088, 1093) and defeated King Alfonso at the Battle of Sagrajas (Zallaqah) in 1086. The event occured when Yusuf ibn Tashfin replied to the call of three Andalusian leaders (Al-Mu’tamid ibn Abbad and others) and crossed to Andalusia. He marched with his army to the north of al-Andalus until he reached az-Zallaqah. The Almoravid army accumulated warriors from all over al-Andalus. Alfonso, realising that he should be ready to confront his enemy went back to his stronghold in Toledo. He called the King of Aragon for help. Some more help came from France and Italy and the two armies started their preparation for the battle, they had their confrontation in Toledo in 1086. The two leaders exchanged messages before the battle. Yusuf ibn Tashfin is reputed to have offered three choices to the Castilians: convert to Islam, to pay tribute (jizyah), or battle. The battle started on Friday at dawn with an attack from Castile. The battle was a decisive victory for the Almoravids. The battle resulted in the defeat of Alfonso and his army and extended the life of the Muslims in Andalucia for three centuries.
In his return to Iberia in 1090, avowedly for the purpose of annexing the taifa states of Iberia. He was supported by the bulk of Iberian peoples, who were discontent with the heavy taxation imposed upon them by their spend-thrift rulers. Their religious teachers, as well as others in the east, (most notably, al-Ghazali in Persia and al-Tartushi in Egypt, who was himself an Iberian by birth, from Tortosa), detested taifa rulers for their religious indifference. The clerics issued a fatwa (a non-binding legal opinion) that Yusuf had good moral and religious right, to dethrone the rulers, whom he saw as heterodox. By 1094, Yusuf had annexed most major taifas, with the exception of the one at Zaragoza. Yusuf did not reconquer much from the Christian kingdoms, except Valencia, but he did slow down the reconquesta by uniting al-Andalus.
After friendly correspondence with the caliph at Baghdad, whom he acknowledged as Amir al-Mu’minin (“Commander of the Faithful”), Yusuf ibn Tashfin in 1097 assumed the title of Amir al Muslimin (“Commander of the Muslims”). He died in 1106, when he was reputed to have reached the age of 100.
The Almoravid power was at its height at Yusuf’s death, and the Moorish empire then included all North-West Africa as far as Algiers, and all of Iberia south of the Tagus, with the east coast as far as the mouth of the Ebro, and included the Balearic Islands.
Ibn Tachafin’s actions halted the southward expansion of the Christian kingdoms. Ibn Tachfin, the victorious was now called the Prince of the Faithful. He was hailed as the saviour of Andalusia and Islam. Marrakech became the capital of that empire in 1091. He was also the first Moroccan king to cross the Straits of Gibraltar.
The Almoravids conquered the Ghana Empire sometime around 1075 CE. According to Arab tradition, the ensuing war pushed Ghana over the edge, ending the kingdom’s position as a commercial and military power by 1100, as it collapsed into tribal groups and chieftaincies, some of which later assimilated into the Almoravids while others founded the Mali Empire. However, the Almoravid religious influence was gradual and not heavily involved in military strife, as Almoravids increased in power by marrying among the nation’s nobility. Scholars such as Dierk Lange attribute the decline of ancient Ghana to numerous unrelated factors, only one of which can be likely attributable to internal dynastic struggles that were instigated by Almalvorid influence and Islamic pressures, but devoid of any military conversion and conquest.
Under Abu Bakr b. Omar (d. 1087), the cousin of Yusuf ibn Tachafin, however, the movement proceeded to Africa in the pursuit of its objectives. They continued their campaign against the non-belivers until the latter agreed to abandon their beliefs. On arrival to the south, Abu Bakr made a base at Azzugi a town on the edge of the Sahara, north of the Senegal River. As the south became Islamised, it became more secure, boosting trade and guaranteeing the flow of gold northwards, enabling the Murabitun there to continue to strike such a coinage in the Maghreb and Andalusia. Certainly, trade could not be the only beneficiary of the Islamisation and pacification of the Sahel and Western Africa. There must have been scholars from the north coming to the south to give a hand in the obviously expanding teaching opportunities and perhaps students from the south going north for further studies. Dearth of written records at this stage of the history of the region will not allow us to say with certainty the volume of traffic of these scholars and students. But the ultimate transformation of the region bears a clear testimony to this scholarly traffic. Similarly, the details of the campaigns of Abu Bakr are not available. It is easy to understand why. The level of education and literacy was low as the culture of learning was just spreading. Scholars must have been busy teaching the basics of Islam with little or no time left for the luxury of compiling chronicles and biographies. But here again the effects of Abu Bakr’s campaigns and the impact of the teachings of the Murabitun scholars was to reveal itself in the speed with which Ghana and its environs became Islamised and the pagan power base withered away paving the way for the emergence of Mali with a clear Muslim power base and unmistakable Islamic leadership. We have been assured, however, that Abu Bakr continued his campaigns non-stop until he died in the year 1087. This means Abu Bakr campaigned in the area for some fifteen years.
Flag of Almoravid dynasty
Moroccan Almohad Caliphate
However, the Christian states in Iberia were becoming too well organized to be overrun by the Muslims, and the Almohads made no permanent advance against them.
In 1212, the Almohad Caliph Muhammad ‘al-Nasir’ (1199–1214), the successor of al-Mansur, after an initially successful advance north, was defeated by an alliance of the four Christian princes of Castile, Aragón, Navarre, and Portugal, at the Battle of Las Navas de Tolosa in the Sierra Morena. The battle broke the Almohad advance, but the Christian powers remained too disorganized to profit from it immediately.
Before his death in 1213, al-Nasir appointed his young ten-year old son as the next caliph Yusuf II “al-Mustansir”. The Almohads passed through a period of effective regency for the young caliph, with power exercised by an oligarchy of elder family members, palace bureaucrats and leading nobles. The Almohad ministers were careful to negotiate a series of truces with the Christian kingdoms, which remained more-or-less in place for next fifteen years (the loss of Alcácer do Sal to the Kingdom of Portugal in 1217 was an exception).
In early 1224, the youthful caliph died in accident, without any heirs. The palace bureaucrats in Marrakesh, led by the wazir Uthman ibn Jam’i, quickly engineered the election of his elderly grand-uncle, Abd al-Wahid I ‘al-Makhlu’, as the new Almohad caliph. But the rapid appointment upset other branches of the family, notably the brothers of the late al-Nasir, who governed in al-Andalus. The challenge was immediately raised by one of them, then governor in Murcia, who declared himself Caliph Abdallah al-Adil. With the help of his brothers, he quickly seized control of al-Andalus. His chief advisor, the shadowy Abu Zayd ibn Yujjan, tapped into his contacts in Marrakesh, and secured the deposition and assassination of Abu al-Wahid I, and the expulsion of the al-Jami’i clan.
This coup has been characterized as the pebble that finally broke al-Andalus. It was the first internal coup among the Almohads. The Almohad clan, despite occasional disagreements, had always remained tightly knit and loyally behind dynastic precedence. Caliph al-Adil’s murderous breach of dynastic and constitutional propriety marred his acceptability to other Almohad sheikhs. One of the recusants was his cousin, Abd Allah al-Bayyasi (“the Baezan”), the Almohad governor of Jaén, who took a handful of followers and decamped for the hills around Baeza. He set up a rebel camp and forged an alliance with the hitherto quiet Ferdinand III of Castile. Sensing his greater priority was Marrakesh, where recusant Almohad sheikhs had rallied behind Yahya, another son of al-Nasir, al-Adil paid little attention to this little band of misfits.
In 1225, Abdallah al-Bayyasi’s band of rebels, accompanied by a large Castilian army, descended from the hills. They raided throughout the regions of Jaén, Cordoba and vega de Granada and, before the end of the year, al-Bayyasi had established himself in the city of Cordoba. Sensing the vacuity, both Alfonso IX of León and Sancho II of Portugal opportunistically ordered their own raids into Andalusian territory that same year. With Almohad arms, men and cash dispatched to Morocco to help Caliph al-Adil impose himself in Marrakesh, there was little means to stop the sudden onslaught. In late 1225, with surprising ease, the Portuguese raiders reached the environs of Seville. Knowing they were outnumbered, the Almohad governors of the city refused to confront the Portuguese raiders, prompting the disgusted population of Seville to take matters into their own hands, raise a militia, and go out in the field by themselves. The result was a veritable massacre – the Portuguese men-at-arms easily mowed down the throng of poorly-armed townsfolk. Thousands, perhaps as much as 20,000, were said to have been slain before the walls of Seville. A similar disaster befell a similar popular levy by Murcians at Aspe that same year. But Christian raiders had been stopped at Cáceres and Requena. Trust in the Almohad leadership was severely shaken by these events – the disasters were promptly blamed on the distractions of Caliph al-Adil and the incompetence and cowardice of his lieutenants, the successes credited to non-Almohad local leaders who rallied defenses.
But al-Adil’s fortunes were briefly bouyed. In payment for Castilian assistance, al-Bayyasi had given Ferdinand III three strategic frontier fortresses: Baños de la Encina, Salvatierra (the old Order of Calatrava fortress near Ciudad Real) and Capilla. But Capilla refused to pass over, forcing the Castilians to lay a long and difficult siege. The brave defiance of little Capilla, and the spectacle of al-Bayyasi’s shipping provisions to the Castilian besiegers, shocked Andalusians and shifted sentiment back towards the Almohad caliph. A popular uprising finally broke out in Cordoba – al-Bayyasi was killed and his head dispatched as a trophy to Marrakesh. But Caliph al-Adil did not relish this victory for long – he was assassinated in Marrakesh in October 1227, by the partisans of Yahya, who was promptly acclaimed as the new Almohad caliph Yahya “al-Mu’tasim”.
The Andalusian branch of the Almohads refused to accept this turn of events. Al-Adil’s brother, then in Seville, proclaimed himself the new Almohad caliph Abd al-Ala Idris I ‘al-Ma’mun’. He promptly purchased a truce from Ferdinand III in return for 300,000 maravedis, allowing him to organize and dispatch the bulk of the Almohad army in Spain across the straits in 1228 to confront Yahya.
That same year, Portuguese and Leonese renewed their raids deep into Muslim territory, basically unchecked. Feeling the Almohads had failed to protect them, popular uprisings ensued throughout al-Andalus. City after city deposed their hapless Almohad governors and installed local strongmen in their place. A Murcian strongman, Muhammad ibn Yusuf ibn Hud al-Judhami, who claimed descendance from the Banu Hud dynasty that had once ruled the old taifa of Zaragoza, emerged as the central figure of these rebellions, systematically dislodging Almohad garrions through central Spain. In October 1228, with Spain practically all lost, al-Ma’mun abandoned Seville, taking what little remained of the Almohad army with him to Morocco. Ibn Hud immediately dispatched emissaries to distant Baghdad to offer recognition to the Abbasid Caliph, albeit taking up for himself a quasi-caliphal title, ‘al-Mutawwakil’.
The departure of al-Ma’mun in 1228 marked the end of the Almohad era in Spain. But Ibn Hud and the other local Andalusian strongmen were unable to stem the rising flood of Christian attacks, launched almost yearly by Sancho II of Portugal, Alfonso IX of León, Ferdinand III of Castile and James I of Aragon. The next twenty years saw a massive advance in the Christian reconquista – the old great Andalusian citadels fell in a grand sweep: Mérida and Badajoz in 1230 (to Leon), Majorca in 1230 (to Aragon), Beja in 1234 (to Portugal), Córdoba in 1236 (to Castile), Valencia in 1238 (to Aragon), Niebla-Huelva in 1238 (to Leon), Silves in 1242 (to Portugal), Murcia in 1243 (to Castile), Jaén in 1246 (to Castile), Alicante in 1248 (to Castile), culminating in the fall of the greatest of Andalusian cities, the ex-Almohad capital of Seville, into Christian hands in 1248. Ferdinand III of Castile entered Seville as a conqueror on December 22, 1248.
The Andalusians were helpless before this onslaught. Ibn Hudd had attempted to check the Leonese advance early on, but the bulk of his Andalusian army was destroyed at the battle of Alange in 1230. Ibn Hud scrambled to move remaining arms and men to save threatened or besieged Andalusian citadels, but with so many attacks at once, it was a hopeless endeavor. After Ibn Hud’s death in 1238, some of the Andalusian cities, in a last-ditch effort to save themselves, offered themselves once again to the Almohads, but to no avail. The Almohads would not return.
With the departure of the Almohads, the Nasrid dynasty (“Banu Nazari” (Arabic: بنو نصر)) rose to power in Granada. After the great Christian advance of 1228-1248, the Emirate of Granada was practically all that remained of old al-Andalus. Some of the captured citadels (e.g. Murcia, Jaen, Niebla) were reorganized as tributary vassals for a few more years, but most were annexed by the 1260s. Granada alone would remain independent for an additional 250 years, flourishing as the new center of al-Andalus
Flag of Almohad dynasty
Moroccan Marinid dynasty
In 1169, the Marinids began their pursuit of taking Morocco from the Almohads, the ruling dynasty at the time. Following their expulsion from the south, they moved northwards under command of Abu Yahya ibn Abd al-Haqq and took Fes in 1248, making it their capital. This marked the beginning of the Marinid dynasty. The Marinid leadership installed in Fes declared war on the Almohads with the aid of Christian mercenaries. Abu Yusuf Yaqub (1259-1286) captured Marrakech in 1269, and then took control of most of the Maghreb towards the end of 1268, including present-day Morocco, Algeria and part of Tunisia. After the Nasrids cession of Algeciras to the Marinidas, Abu Yusuf went to Andalusia to support them in their struggle against the Kingdom of Castile. Having obtained this control, the Marinid dynasty tried to extend its control to the commercial traffic of the Strait of Gibraltar. To this end, they declared jihad on the Christians and occupied the cities of Rota, Algiers and Gibraltar successively, surrounding Tarifa for the first time in 1294. Internal power struggles among the Marinids followed, which didn’t however prevent Abu Said Uthman II (1310-1331) from substantial construction work in Fez. Several madrasas for the education of public servants were founded, in order to support the centralization of administration and to reduce the influence of the Marabous. The Marinids also strongly influenced the policy of the Kingdom of Granada, from which they enlarged their army in 1275. In the mid 1300, Castile made several incursions into Morocco and in 1267 a full-scale invasion of Morocco, but the Marinids successfully defended Morocco and drove out the Castilians. Under Abu al-Hasan (1331-1348) another attempt to reunite the Maghreb was made. In 1337 the empire of the Abdalwadids in (what is now called) Algeria was conquered, followed in 1347 by the empire of the Hafsids in Ifriqiya (Tunisia). However in 1340 the Marinids suffered a crushing defeat at the hands of a Portuguese-Castilian coalition at the Battle of Rio Salado, and finally had to withdraw from Andalusia. There was Portuguese activity in northern Morocco: Ceuta (Sebta) was conquered by the Portuguese in 1415, and taken by Spain in 1580. Mellilla was conquered by Spain in 1497.
Abul Hassan was deposed by his son Abu Inan Faris (1348-1358), who reconquered the central Maghreb (Algeria and Tunisia). Despite several successes, the dynasty began to decline after the murder of Abu Inan Faris, strangled by his own vizier in 1358.
After the death of Abu Inan Faris in 1358, the real power lay with the viziers, while the Marinid sultans were paraded and forced to succeed each other in quick succession. The county was divided and political anarchy set in, with different viziers and foreign powers supporting different factions. In 1359 Hintata tribesmen from the High Atlas came down and occupied Marakesh, capital of their Almohad ancestors, which they would govern independently until 1526. To the south of Marakesh, Sufi mystics claimed autonomy, and in the 1370s Azemmour broke off under a coalition of merchants and Arab clan leaders of the Banu Sabih. To the east, the Zianid and Hafsid families reemerged and to the north, the Europeans were taking advantage of the Moroccan instability by attacking the Moroccan coast. Meanwhile, unruly wandering Arab Bedouin tribes increasingly spread anarchy in Morocco, which accelerated the decline of the empire.
In the 15th century Morocco was hit by a financial crisis, after which the state had to stop financing the different marabouts and Sharifian families, which had previously been useful instruments in controlling the country. The political support of these marabouts and Sharifians halted, and Morocco splintered into different entities. In 1399 Tetouan was taken and its population was massacred and in 1415 the Portuguese captured Ceuta. After the sultan Abdalhaqq II (1421–1465) tried to break the power of the wattasids, he was executed. Marinid rulers after 1420 came under the control of the Wattasids, who exercised a regency as Abd al-Haqq II became Sultan one year after his birth. The Wattasids however refused to give up the Regency after Abd al-Haqq came to age.In 1459, Abd al-Haqq II managed a massacre of the Wattasid family, breaking their power. His reign, however, brutally ended as he was murdered during the 1465 revolt.This event saw the end of the Marinid dynasty as Muhammad ibn Ali Amrani-Joutey, leader of the Sharifs, was proclaimed Sultan in Fes. He was in turn overthrown in 1471 by Muhammad ibn Yahya al-Sheikh, one of the two the surviving Wattasids from the 1459 massacre, who instaured the Wattasid dynasty.
Flag of Marinid dynasty, used along with a white banner