Islam was first brought to Morocco in 680 by an Arab invasion under Uqba ibn Nafi, who was a general serving under the Umayyads of Damascus. In 788, The Zaydi Shia Idrisids ruled large parts of Morocco. Their contemporaries included the heretical Barghawata state and the Khariji state of Sijilmasa. Later, several Berbers formed more powerful Islamic dynasties that reigned over the country. Among them were the Almoravids (1040–1147), who were the first to unite Morocco, as well as significant regions in West Africa, Spain and Algeria. The Almoravids were responsible for making the Maliki school of Islamic jurisprudence the most prominent in Morocco. It was later under Almohad rule (1121-1269) that smaller Muslim sects were persecuted and orthodox Sunni Islam became prevalent across the country.
Muslims in Morocco are predominantly of the Maliki madhab, or school of thought. The administration of King Mohammed VI has combated the influence of Salafi Islam via a state program where 100,000 imams will go to the country’s 50,000 mosques and promote the moderate Islam of the Maliki madhab.