The Almoravids, or Men of the Ribat, were a large tribe of Berbers that detached themselves from the Empire of the Songhai to seek conquests for their own kingdom farther North. The success of their invasion of the Berber Kingdom of Mauretania in 1060-1061 allowed them to form this kingdom, which remained in their hands for about 100 years.
Rebellion against the Songhai
The Almoravids were a particularly aggressive sect of Sahel Berbers from the north of the Songhai Empire, whose shamanist religion was particularly strong - and fast developing into a monotheistic religion. Angry with the impotence of the Songhai Emperor, the leader of Almoravids, Murabit Yusuf plotted for the dynasty's overthrow. The Songhai dynasty, which had ruled the Niger valley for almost 200 years, were more competent than Yusuf supposed and by 1052 the rebellion had been crushed - and the remnants of the Almoravids fled into the semi-desert that bordered the Sahara.
As it turned out, the Almoravids maintained their precarious existence on the northern border for several years, leading occasional raid into Songhai lands, which, though ultimately rebuffed, were never beaten. The Almoravids maintained their aggressive tenacity, but also developed a strong fighting force. When Murabit Yusuf died in 1058, the sect had never looked stronger. Yusuf's son, Murabit Yusuf Khalifah immediately commissioned an invasion of the Songhai Empire. However, many of the older members of his council refused to allow this, due to their fear that the Songhai would repeat the devastation of 1052, so Yusuf Khalifah turned his attention to other possibilities. Stories of a land made of gold had been passed from the Berber nomads of the Sahara; this immediately grabbed the wildest dreams of Yusuf, who ordered the wholesale migration of the sect northwards.
War with Mauretania
The migration was initially a great disappointment; they found not the Land of Gold that they had been seeking, but a desert kingdom comparable in many ways to their own. The Berber Kingdom of Mauretania had been encountered for the first time. One way the Mauretanians could not compete, however, was on the field of war; this was soon established at the Battle of Sijilmasa Oasis, where Yusuf Khalifah had no trouble whatsoever in defeating his opposite number.
Foundation of Marrakesh
The Almoravids spent the next three years establishing themselves artound the Sijilmasa Oasis, a wealthy trading station - and a great loss to the Berber state. However, Almoravid administration soon exhausted the Oasis' limited resources, and, once again, Yusuf Khalifah followed his soothsayers and continued the northern advance. The Berbers had made little use of the 3 year interval in the war against the Almoravids; the best they could manage was to send the Crown Prince, Bocchus, south with a frankly inadequate army, to hold the Almoravids in place. Bocchus was a man of a chivalrous, but foolish, disposition, and - on a field of Mauretanian choosing - the two sides did battle. This conflict, later entitled the Battle of Marrakesh, ended in complete victory for Yusuf Khalifah; evidently Bocchus' choosing was not as adequate as he had foreseen. On the sight of the victory, Yusuf Khalifah decided to commemorate his successes by the construction of a new capital on the sight of the battle.
Continuation of the Campaign
Insulted by Bocchus arrogance after his capture, Yusuf Khalifah had him executed and his body dumped in a nearby river. By comparison, the mildness with which he treated the other Berber prisoners soon spread around the entire Maghreb, causing thousands to offer homage to the Almoravid government at Marrakesh. Immigration was staggering; few now wanted to be associated with the enemies of the mighty Murabit Yusuf Khalifah. However, in practical terms, Yusuf Khalifah still had a job on his hands; all of the major cities in the Western Maghreb, bar Marrakesh, were still in the hands of the Mauretanian monarchy. This threat, however, was pretty much eliminated by the capture of Fez, the most powerful of the Berber citadels, in a matter of days.
The Battle of Kairuoan
The rest of the Maghreb fell rather quickly after that, with the fall of the old capital, Tingis (November 1060), Bougie (January 1061), Mazaka (February 1061) and finally the fall of the capital, Cirta, in April. The ruling monarch, Maharbal II, fled with his wife and two surviving sons, to Kairuoan, on the border of the Byzantine's African province. Their they met, and defeated, the army of the semi independent Byzantine governor, Attalus Gazienus, after which they persuaded the dubious Greek into aiding them against the Almoravids. Attalus was inclined to refuse at first, but he was ultimately persuaded when Maharbal paid two of his own officials to arrest him. On the field of battle, somewhere between Kairuoan and Utica, the battle was fought. This battle ended in complete victory for the Almoravids. Maharbal and his sons went down fighting. The Berber dynasty of Mauretania had been extinguished.
The Carthago Crisis - Friction with Byzantium
Now there was no power capable of stopping the Almoravids from taking over the entire Maghreb, since the intrigues of the Byzantines were facing East, towards the Seljuk Empire. On his own, Attalus, the above mentioned governor of Africa (the Roman province centered around Carthage), was incapable of stemming the tide of Yusuf's forces. In the November of 1061, Attalus was slain during a skirmish in Utica. By 1062, only Carthage was left in the hands of the Greek governors - in this case, Attalus' nephew Nicodemus. The port of Carthage (known thereon as the Principality of Carthago) was felt fit to be spared by Yusuf, as a Greek city subject to Almoravid rule.
Events in the Maghreb were slow to reach Byzantine ears, but when Romanus V heard of these developments, he reacted with displeasure. The loss of Africa had been on the cards for a while; what really worried the emperor was the disloyalty shown by Attalus, Nicodemus and the Gazienid dynasty that they had founded. Therefore, in 1066, the emperor sent officials to Carthage to arrest Nicodemus. The Byzantine fleet arrived at Carthage, where they were received openly by the Almoravid prefect charged with keeping the area in line with Almoravid policy. The Almoravids had no idea of the true power of the Byzantines, or indeed of their motives in the area, but when they caught the Byzantine officials attacking Nicodemus' palace in Carthage, they reacted accordingly. The Almoravid army residing at Kairuoan was called in and word was sent to Yusuf, who now went by the title of Grand Sharif or Great King of the Berber Sheikhs, who was at Marrakesh. The Byzantine officials were then arrested and beheaded on the spot - there bodies sent back to the fleet with the message:
Here be the punishment for those on Berber lands, who assert their authority where it is not wanted.
The Byzantines were understandably upset about this - and though their fleet was still in port, the Almoravids drove it off with mangonels and angry cries. In 1067, Romanus ordered an army to be assembled by the governor of Egypt, which would set sail from Kyrene and attack. Thankfully for Yusuf's newly formed empire, this force never reached Carthage; it was redirected in the wake of the Seljuk war of 1070. Due to the devastating effects of this war, Romanus was not again able to muster the force necessary to attack the Maghreb. The Almoravids had been saved.
The Golden Age of Almoravid Rule
Murabit Yusuf Khalifah continued to rule his North African empire until 1075. During this time, he repaired and replaced institutions damaged by his wars against the Berber Kingdom of Mauretania. Seeing the need for a strong fleet, he acquired the services of the merchant guilds of Carthage, in return for trading concessions in the Almoravid port cities. As a result, trade boomed - and the Almoravids were able to establish a navy of exceptional quality, exceeded only by Byzantium and Septimania The tradition of firm and steady economic progress was continued by his son Murabit Yusuf Tariq, who ruled from 1075 until 1092. The Murabit family then had a monopoly of monarchs in the Maghreb until 1140 - and the Sharifate of Fez and family enclaves at Thapsus and Kairuoan lasted further into the future.
Collapse of the Almoravid Hegemony
As mentioned above, Almoravid rule over the entirety of the Maghreb could only last so long. Emnities against the Empire of the Songhai had caused incursions by the Almoravids since the days of Yusuf Khalifah, but in 1131, Murabit Yusuf Tariq II commissioned a full scale invasion. The logistics of such an attack were difficult and certainly beyond the administration of the noticeably ageing Almoravid Empire. The Songhai had no trouble in bringing their counterattack to a successful conclusion at the pitched battle of Fort Niger, where the Almoravid army was all but annihilated. Tariq returned home to face rebellion and - being unable to quell it - committed suicide. In the end it was his son, Murabit Yusuf Tariq Abdullah who restored order, defeating the armies of principal rivals Sheikh Merin I and Muwahhid Abdul Yusuf at the battle of Bomika. However, Tariq Abdullah began to get a little above himself, threatening both a further invasion of the Songhai and a raid on Byzantine Egypt. This was something that could be tolerated by neither power; the Songhai attacked the southern border in 1133, followed by a combined attack from land and sea by the Byzantines in 1136. Thankfully, Tariq Abdullah's cousin Murabit Abu Saed defeated the Byzantines at Sabratha, whilst Tariq himself held off the Songhai attacks. Sadly for the Murabit family, their overstretched forces placed temptation again in the path of Muwahhid Abdul Yusuf, who was hiding in the central Algerian desert. Having assassinated Sheikh Merin and his brother Sheikh Abu Wad, he then took control of their forces and marched on Bougie, which he captured in 1138, followed by Constantine and Algiers in 1139. By 1140, he controlled the whole of Algeria. Only Marrakesh, Tingis and Fez remained in the hands of Murabit Yusuf Tariq Abdullah, whilst Kairuoan remained under the despotic rule of Murabit Abu Saed. Abu's brother, Murabit Bomilca Saed, remained ruler of Thapsus by popular support until his death in 1155, when it was annexed by the Byzantines (following Carthage, which was annexed the previous year!).