quality:corruption
In al-Andalus during the Umayyad caliphate

New waves of Berber settlers arrived in al-Andalus in the 10th century, brought as mercenaries by Abd ar-Rahman III, who proclaimed himself caliph in 929, to help him in his campaigns to restore Umayyad authority in areas that had overthrown it during the reigns of the previous emirs. These new Berbers "lacked any familiarity with the pattern of relationships" that had existed in al-Andalus in the 700s and 800s; thus they were not involved in the same web of traditional conflicts and loyalties as the previously already existing Berber garrisons.

New frontier settlements were built for the new Berber mercenaries. Written sources state that some of the mercenaries were placed in Calatrava, which was refortified. Another Berber settlement called Vascos, west of Toledo, is not mentioned in the historical sources, but has been excavated archaeologically. It was a fortified town, had walls, and a separate fortress or alcazar. Two cemeteries have also been discovered. The town was established in the 900s as a frontier town for Berbers, probably of the Nafza tribe. It was abandoned soon after the Castilian occupation of Toledo in 1085. The Berber inhabitants took all their possessions with them.

In the 900s, the Umayyad caliphate faced a challenge from the Fatimids in North Africa. The Fatimid Caliphate of the 10th century was established by the Kutama Berbers. After taking the city of Kairouan and overthrowing the Aghlabids in 909, the Mahdi Ubayd Allah was installed by the Kutama as Imam and Caliph, which posed a direct challenge to the Umayyad's own claim. The Fatimids gained overlordship over the Idrisids, then launched a conquest of the Maghreb. To counter the threat, the Umayyads crossed the strait to take Ceuta in 931, and actively formed alliances with Berber confederacies, such as the Zenata and the Awraba. Rather than fighting each other directly, the Fatimids and Umayyads competed for Berber allegiances. In turn, this provided a motivation for the further conversion of Berbers to Islam, many of the Berbers, particularly farther south, away from the Mediterranean, being still Christian and pagan. In turn, this would contribute to the establishment of the Almoravid dynasty and Almohad Caliphate, which would have a major impact on al-Andalus and contribute to the end of the Umayyad caliphate.

With the help of his new mercenary forces, Abd ar-Rahman launched a series of attacks on parts of the Iberian peninsula that had fallen away from Umayyad allegiance. In the 920s he campaigned against the areas that rebelled under Umar ibn Hafsun and refused to submit until the 920s. He conquered Mérida in 928–929, Ceuta in 931, and Toledo in 932. In 934 he began a campaign in the north against Ramiro II of Leon and Muhammad ibn Hashim al-Tujibi, the governor of Zaragoza. According to Ibn Hayyan, after inconclusively confronting al-Tujibi on the Ebro, Abd ar-Rahman briefly forced the Kingdom of Pamplona into submission, ravaged Castile and Alava, and met Ramiro II in an inconclusive battle. From 935 to 937, he confronted the Tujibids, defeating them in 937. In 939, Ramiro II defeated the combined Umayyad and Tujibid armies in the Battle of Simancas.

Umayyad influence in western North Africa spread through diplomacy rather than conquest. The Umayyads sought out alliances with various Berber confederacies. These would declare loyalty to the Umayyad caliphate in opposition to the Fatimids. The Umayyads would send gifts, including embroidered silk ceremonial cloaks. During this time, mints in cities on the Moroccan coast— Fes, Sijilmasa, Sfax, and al-Nakur—occasionally issued coins with the names of Umayyad caliphs, showing the extent of Umayyad diplomatic influence. The text of a letter of friendship from a Berber leader to the Umayyad caliph has been preserved in the work of 'Isa al-Razi.

During Abd ar-Rahman's reign, tensions increased between the three distinct components of the Muslim community in al-Andalus: Berbers, Saqaliba (European slaves), and those of Arab or mixed Arab and Gothic descent. Following Abd ar-Rahman's proclamation of the new Umayyad caliphate in Cordoba, the Umayyads placed a great emphasis on the Umayyad membership of the Quraysh tribe. This led to a fashion, in Cordoba, for claiming pure Arab ancestry as opposed to descent from freed slaves. Claims of descent from Visigothic noble families also became common. However, an "immediately detrimental consequence of this acute consciousness of ancestry was the revival of ethnic disparagement, directed in particular against the Berbers and the Saqaliba".

When the Fatimids moved their capital to Egypt in 969, they left north Africa in charge of viceroys from the Zirid clan of Sanhaja Berbers, who were Fatimid loyalists and enemies of the Zenata. The Zirids in turn divided their territories, assigning some to the Hammadid branch of the family to govern. The Hammadids became independent in 1014, with their capital at Qal'at Beni-Hammad. With the withdrawal of the Fatimids to Egypt, however, the rivalry with the Umayyads decreased.

Al-Hakam II sent Muhammad Ibn Abī ‘Āmir to north Africa in 973–974 to act as qadi al qudat (chief justice) to the Berber groups that had accepted Umayyad authority. Ibn Abī ‘Āmir was treasurer of the household of the caliph's wife and children, director of the mint at Madinat al-Zahra, commander of the Cordoba police, and qadi of the frontier. During his time as qadi in north Africa, Ibn Abi Amir developed close ties with the North African Berbers.

Considerable resentment arose in Cordoba against the increasing numbers of Berbers brought from north Africa by al-Mansur and his children Abd al-Malik and Sanchuelo. It was said that Sanchuelo ordered anyone attending his court to wear Berber turbans, which Roger Collins suggests may not have been true, but shows that hostile anti-Berber propaganda was being used to discredit the sons of al-Mansur. In 1009, Sanchuelo had himself proclaimed Hisham II's successor, and then went on military campaign. However, while he was away a revolt took place. Sanchuelo's palace was sacked and his support fell away. As he marched back to Cordoba his own Berber mercenaries abandoned him. Knowing the strength of ill feeling against them in Cordoba, they thought Sanchuelo would be unable to protect them, and so they went elsewhere in order to survive and secure their own interests. Sanchuelo was left with only a few followers, and was captured and killed in 1009. Hisham II abdicated and was succeeded by Muhammad II al-Mahdi.

Having abandoned Sanchuelo, the Berbers who had formed his army turned to support another ambitious Umayyad, Sulayman. They obtained logistical support from Count Sancho Garcia of Castile. Marching on Cordoba, they defeated Saqaliba general Wadih and forced Muhammad II al-Mahdi to flee to Toledo. They then installed Sulayman as caliph, and based themselves in the Madinat al-Zahra to avoid friction with the local population. Wadih and al-Mahdi formed an alliance with the Counts of Barcelona and Urgell and marched back on Cordoba. They defeated Sulayman and the Berber forces in a battle near Cordoba in 1010. To avoid being destroyed, the Berbers fled towards Algeciras.

Al-Mahdi swore to exterminate the Berbers and pursued them. However, he was defeated in battle near Marbella. With Wadih, he fled back to Cordoba while his Catalan allies went home. The Berbers turned around and besieged Cordoba. Deciding that he was about to lose, Wadih overthrew al-Mahdi and sent his head to the Berbers, replacing him with Hisham II. However, the Berbers did not end the siege. They methodically destroyed Cordoba's suburbs, pinning the inhabitants inside the old Roman walls and destroying the Madinat al-Zahra. Wadih's allies killed him, and the Cordoba garrison surrendered with the expectation of amnesty. However, "a massacre ensued in which the Berbers took revenge for many personal and collective injuries and permanently settled several feuds in the process". The Berbers made Sulayman caliph once again. Ibn Idhari said that the installation of Sulayman in 1013 was the moment when "the rule of the Berbers began in Cordoba and that of the Umayyads ended, after it had existed for two hundred and sixty eight years and forty-three days".