Supported by the Berbers, he began to fight against the Abbasid caliphs. Named chief, he founded the first Muslim (Arabic) dynasty of the Idrissids who reigned from 788 to 829.

As a ruler, Idriss ruled the northern territory of today's Morocco. He settled in a small village that he wanted to expand into his future capital, which was accomplished by his son, Idriss Il (between 803-829), and the new city was called Fez. The death of Idriss II was followed by struggles between eleven viziers, the son of Idris II, wishing to take Berber powers - defenders of the faith.

The weakening of the country benefited the Almoravids, the first dynasty of Berber origin that reigned over Morocco.

The Almoravids, who claimed to be defenders of the Muslim faith, strengthened the country by taking power over the north of present-day Morocco and Algeria after the victory of Youssef bene Tachfin who conquered Fez in 1069.

The new rulers transferred the capital to Marrakech, which they built in 1071. They also conquered the Iberian peninsula, allowing a free exchange of Arab art and culture from Al Andalus (Andalusia) to Moroccan territory .

As they grew more prosperous, the report of the Almoravids towards the region became more liberal. This benefited their enemies, the Almohads, who condemned excesses and unworthy leisure, such as the consumption of alcohol, dances with women, or even too daring outfits.

The Almohads were faithful to the strict rule proclaimed by Abu Abd Allah Mohammad Ibn Tumart (1080-1128), the first ruler of this dynasty who criticized the excesses and initiated the holy war. One of the most illustrious rulers of the Almohad dynasty, Yaqub al-Mansur (1184-1199) defeated the Christian army of Alfonso VIII of Castile in 1193 near Alarcos, in the Iberian peninsula. The Bou Mania medersa is a symbol of the heyday of the Marinides' reign.

The Almohades possessed the lands from the Atlantic to Barkah in Cyrenaica. Thanks to reforms, including tax reforms, the country flourished, art and culture were experiencing their revival and trade brought enormous benefits.

In Marrakech, the Almohads built the Koutoubia mosque, in Seville the minaret Giralda, and in Rabat they began construction of the mosque of Hassan (nowadays only the tower of Hassan remains) which was never finalized.

After years of prosperity, the first failures took place, the most important of which was the loss near Las Navas de Tolosa (1212). The Castilian army began, gently but efficiently, to drive the Almohades from the Iberian peninsula. The weakened country was invaded by the nomad tribes Banu Marin (Merinides) who defeated the Almohads in 1269.

Culture and gold: the days of the Merinids and the Saadians The Merinids, who ruled from the middle of the sixties. Until the middle of the 15th century, began with the centralization of the country. They transferred the capital to Fez, where they built a palace with, next to it, a mellah, a Jewish quarter.

It was during their reign that intellectual and cultural life flourished, and they also founded the largest number of Muslim superior schools (medersas) in the whole history of Morocco.

The architectural masterpieces of the period included the Koranic schools of Bou Inania in Fez and Meknes and the mausoleum of Chellah in Rabat.

The governance of the Mérinides being very calm, Morocco was "invaded" by Jews and Muslims of the Iberian Peninsula, among whom craftsmen and specialists in several fields. The sovereigns took advantage of their potential: the period of the Merinids was marked by important scientific discoveries.

Abu Abdullah Muhammad Ibn Batouta, a Moroccan Marco Polo, visited the entire Muslim world of his time and the result of these voyages was an important work of the field of geography: Particularities of the cities and strangeness of the voyages 1325-1354.

Equally important was the Book of Considerations on the History of the Arabs, Persians and Berbers of the Historian Ibn Khaldun. In the second half of the 14th century, Morocco was divided into three parts and the Merinids had to govern at a difficult time of division. The most important centers were then Fez, Marrakech and Rissani.