Earlier in the century a Berber dynasty of austere, conservative Muslims known as the Almoravids had conquered Morocco in northwest Africa, and in 1085 they set their sights on al-Andalus. They invaded and began what amounted to a full-blooded takeover of all the petty Islamic taifa kingdoms, whose rulers they scorned as decadent, weak-willed, and ripe for removal. Neither did the Almoravids hold the Christian kings of the northern kingdoms in very high regard. In 1086 they took aim at Alfonso of Castile: in October an Almoravid army crushed a Castilian one at the battle of Sagrajas.

