 Islam was first brought to Morocco in 680 by an Arab invasion under the 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.