After Alfonso VI, King of León and Castile, captured Toledo in 1085 and invaded the taifa of Zaragoza, the emirs of the smaller taifa kingdoms of Islamic Iberia found that they could not resist him without external assistance. In 1086, they invited Yusuf ibn Tashfin to fight against Alfonso VI. In that year, he replied to the call of three Andalusian leaders (Al-Mu'tamid ibn Abbad and others) and crossed the straits to Algeciras and moved to Seville. From there, accompanied by the emirs of Seville, Granada, and Taifa of Málaga, he marched to Badajoz.
Alfonso VI abandoned the siege of Zaragoza, recalled his troops from Valencia, and appealed to Sancho I of Aragon for help. Finally he set out to meet the enemy northeast of Badajoz. The two armies met each other on 23 October 1086.
The battle was a decisive victory for the Almoravids but their losses meant that it was not possible to follow it up although Yusuf had to return prematurely to Africa due to the death of his heir. Castile suffered almost no loss of territory and was able to retain the city of Toledo, occupied the previous year. However, the Christian advance was halted for several generations while both sides regrouped.