The Berbers of the Tamazgha in the early Middle Ages could be roughly classified into three major groups: the Zenata across the north, the Masmuda concentrated in central Morocco, and the Sanhaja, clustered in two areas: the western part of the Sahara and the hills of the eastern Maghreb.
The eastern Sanhaja included the Kutama Berbers, who had been the base of the Fatimid rise in the early 10th century, and the Zirid dynasty, who ruled Ifriqiya as vassals of the Fatimids after the latter moved to Egypt in 972.
The western Sanhaja were divided into several tribes: the Gazzula and the Lamta in the Draa valley and the foothills of the Anti-Atlas range; further south, encamped in the western Sahara, were the Massufa, the Lamtuna and the Banu Warith; and most southerly of all, the Gudala, in littoral Mauritania down to the borderlands of the Senegal River.

The western Sanhaja had been converted to Islam some time in the 9th century.
They were subsequently united in the 10th century and, with the zeal of new converts, launched several campaigns against the "Sudanese" (pagan peoples of sub-Saharan Africa).
Under their king Tinbarutan ibn Usfayshar, the Sanhaja Lamtuna erected (or captured) the citadel of Awdaghust, a critical stop on the trans-Saharan trade route.
After the collapse of the Sanhaja union, Awdagust passed over to the Ghana empire; and the trans-Saharan routes were taken over by the Zenata Maghrawa of Sijilmassa.
The Maghrawa also exploited this disunion to dislodge the Sanhaja Gazzula and Lamta out of their pasturelands in the Sous and Draa valleys.
Around 1035, the Lamtuna chieftain Abu Abdallah Muhammad ibn Tifat (alias Tarsina), tried to reunite the Sanhaja desert tribes, but his reign lasted less than three years.

Around 1040, Yahya ibn Ibrahim, a chieftain of the Gudala (and brother-in-law of the late Tarsina), went on pilgrimage to Mecca.
On his return, he stopped by Kairouan in Ifriqiya, where he met Abu Imran al-Fasi, a native of Fes and a jurist and scholar of the Sunni Maliki school.
At this time, Ifriqiya was in ferment.
The Zirid ruler al-Muizz ibn Badis, was openly contemplating breaking with his Shi'ite Fatimid overlords in Cairo, and the jurists of Kairouan were agitating for him to do so.
Within this heady atmosphere, Yahya and Abu Imran fell into conversation on the state of the faith in their western homelands, and Yahya expressed his disappointment at the lack of religious education and negligence of Islamic law among his southern Sanhaja people.
With Abu Imran's recommendation, Yahya ibn Ibrahim made his way to the ribat of Waggag ibn Zelu in the Sous valley of southern Morocco, to seek out a Maliki teacher for his people.
Waggag assigned him one of his residents, Abdallah ibn Yasin.

Abdallah ibn Yasin was a Gazzula Berber, and probably a convert rather than a born Muslim.
His name can be read as "son of Ya Sin" (the title of the 36th Sura of the Qur'an), suggesting he had obliterated his family past and was "re-born" of the Holy Book.
Ibn Yasin certainly had the ardor of a puritan zealot; his creed was mainly characterized by a rigid formalism and a strict adherence to the dictates of the Qur'an, and the Orthodox tradition. (
Chroniclers such as al-Bakri allege Ibn Yasin's learning was superficial.)
Ibn Yasin's initial meetings with the Gudala people went poorly.
As he had more ardor than depth, Ibn Yasin's arguments were disputed by his audience.
He responded to questioning with charges of apostasy and handed out harsh punishments for the slightest deviations.
The Gudala soon had enough and expelled him almost immediately after the death of his protector, Yahya ibn Ibrahim, sometime in the 1040s.

Ibn Yasin, however, found a more favorable reception among the neighboring Lamtuna people.
Probably sensing the useful organizing power of Ibn Yasin's pious fervor, the Lamtuna chieftain Yahya ibn Umar al-Lamtuni invited the man to preach to his people.
The Lamtuna leaders, however, kept Ibn Yasin on a careful leash, forging a more productive partnership between them.
Invoking stories of the early l
The Berbers of the Tamazgha in the early Middle Ages could be roughly classified into three major groups: the Zenata across the north, the Masmuda concentrated in central Morocco, and the Sanhaja, clustered in two areas: the western part of the Sahara and the hills of the eastern Maghreb. The eastern Sanhaja included the Kutama Berbers, who had been the base of the Fatimid rise in the early 10th century, and the Zirid dynasty, who ruled Ifriqiya as vassals of the Fatimids after the latter moved to Egypt in 972. The western Sanhaja were divided into several tribes: the Gazzula and the Lamta in the Draa valley and the foothills of the Anti-Atlas range; further south, encamped in the western Sahara, were the Massufa, the Lamtuna and the Banu Warith; and most southerly of all, the Gudala, in littoral Mauritania down to the borderlands of the Senegal River.
The western Sanhaja had been converted to Islam some time in the 9th century. They were subsequently united in the 10th century and, with the zeal of new converts, launched several campaigns against the "Sudanese" (pagan peoples of sub-Saharan Africa). Under their king Tinbarutan ibn Usfayshar, the Sanhaja Lamtuna erected (or captured) the citadel of Awdaghust, a critical stop on the trans-Saharan trade route. After the collapse of the Sanhaja union, Awdagust passed over to the Ghana empire; and the trans-Saharan routes were taken over by the Zenata Maghrawa of Sijilmassa. The Maghrawa also exploited this disunion to dislodge the Sanhaja Gazzula and Lamta out of their pasturelands in the Sous and Draa valleys. Around 1035, the Lamtuna chieftain Abu Abdallah Muhammad ibn Tifat (alias Tarsina), tried to reunite the Sanhaja desert tribes, but his reign lasted less than three years.
Around 1040, Yahya ibn Ibrahim, a chieftain of the Gudala (and brother-in-law of the late Tarsina), went on pilgrimage to Mecca. On his return, he stopped by Kairouan in Ifriqiya, where he met Abu Imran al-Fasi, a native of Fes and a jurist and scholar of the Sunni Maliki school. At this time, Ifriqiya was in ferment. The Zirid ruler al-Muizz ibn Badis, was openly contemplating breaking with his Shi'ite Fatimid overlords in Cairo, and the jurists of Kairouan were agitating for him to do so. Within this heady atmosphere, Yahya and Abu Imran fell into conversation on the state of the faith in their western homelands, and Yahya expressed his disappointment at the lack of religious education and negligence of Islamic law among his southern Sanhaja people. With Abu Imran's recommendation, Yahya ibn Ibrahim made his way to the ribat of Waggag ibn Zelu in the Sous valley of southern Morocco, to seek out a Maliki teacher for his people. Waggag assigned him one of his residents, Abdallah ibn Yasin.
Abdallah ibn Yasin was a Gazzula Berber, and probably a convert rather than a born Muslim. His name can be read as "son of Ya Sin" (the title of the 36th Sura of the Qur'an), suggesting he had obliterated his family past and was "re-born" of the Holy Book. Ibn Yasin certainly had the ardor of a puritan zealot; his creed was mainly characterized by a rigid formalism and a strict adherence to the dictates of the Qur'an, and the Orthodox tradition. (Chroniclers such as al-Bakri allege Ibn Yasin's learning was superficial.) Ibn Yasin's initial meetings with the Gudala people went poorly. As he had more ardor than depth, Ibn Yasin's arguments were disputed by his audience. He responded to questioning with charges of apostasy and handed out harsh punishments for the slightest deviations. The Gudala soon had enough and expelled him almost immediately after the death of his protector, Yahya ibn Ibrahim, sometime in the 1040s.
Ibn Yasin, however, found a more favorable reception among the neighboring Lamtuna people. Probably sensing the useful organizing power of Ibn Yasin's pious fervor, the Lamtuna chieftain Yahya ibn Umar al-Lamtuni invited the man to preach to his people. The Lamtuna leaders, however, kept Ibn Yasin on a careful leash, forging a more productive partnership between them. Invoking stories of the early l
Almoravid dynasty