After allying with the Sufri Kharijite rebellion in Morocco against the Umayyads, they established an independent state (CE 744 - 1058) in the area of Tamesna on the Atlantic coast between Safi and Salé under the leadership of Tarif al-Matghari.
Fired up by Sufrite (Kharijite) activists, the Berber tribes of western Morocco (the Ghomara, Miknasa and Berghwata) formed a coalition and acclaimed the Berber chieftain Maysara al-Matghari as 'caliph'.