In 1086
Yusuf ibn Tashfin was invited by the taifa Muslim princes of the Iberian Peninsula (Al-Andalus) to defend them against Alfonso VI, King of León and Castile. In that year, Yusuf ibn Tashfin crossed the straits to Algeciras, inflicted a severe defeat on the Christians at the Battle of az-Zallaqah (Battle of Sagrajas). He was prevented from following up his victory by trouble in Africa, which he had to settle in person.
When he returned to Iberia in 1090, it was avowedly for the purpose of deposing the Muslim princes, and annexing their states. He had in his favour the mass of the inhabitants, who had been worn out by the oppressive taxation imposed by their spend-thrift rulers. Their religious teachers, as well as others in the east, (most notably, al-Ghazali in Persia and al-Tartushi in Egypt, who was himself an Iberian by birth, from Tortosa), detested the native Muslim princes for their religious indifference, and gave Yusuf a fatwa -- or legal opinion—to the effect that he had good moral and religious right, to dethrone the rulers, whom he saw as heterodox and who did not scruple to seek help from the Christians, whose habits he claimed they had adopted. By 1094, he had removed them all, except for the one at Zaragoza; and though he regained little from the Christians except Valencia, he re-united the Muslim power, and gave a check to the reconquest of the country by the Christians.