from the taifas of Zaragoza and Lérida, as well as from internal disputes, as Barcelona suffered a dynastic crisis that led to open war among the smaller counties. But by the 1080s, the situation had calmed down, and the dominion of Barcelona over the smaller counties was restored. Almohads After a brief period of disintegration (the second Taifa period), the Almohads, the rising power in North Africa, took over most of Al-Andalus. However they were decisively defeated at the Battle of Las Navas de Tolosa (1212) by a Christian coalition, losing almost all the remaining lands of Al-Andalus in the following decades. By 1252 only the Emirate of Granada remained intact but as a vassal state of Castile. Granada War and the end of Muslim rule Ferdinand and Isabella completed the Reconquista with a war against the Emirate of Granada that started in 1482 and ended with Granada's surrender on 2 January 1492. The Moors in Castile previously numbered "half a million within the realm". By 1492 some 100,000 had died or been enslaved, 200,000 had emigrated, and 200,000 remained in Castile. Many of the Muslim elite, including Granada's former Emir Muhammad XII, who had been given the area of the Alpujarras mountains as a principality, found life under Christian rule intolerable and emigrated to Tlemcen in North Africa. In 1497 Spanish forces took Melilla, west of Oran, and the island of Djerba, south of Tunis, and went on to more important gains, with the bloody seizure of Oran in 1509, and the capture of Bougie and Tripoli in 1510. The Spanish capture of Tripoli cost them some 300 men, while the inhabitants suffered between 3,000 and 5,000 killed and another 5,000–6,000 carried off as slaves. Soon thereafter, however, they faced competition from the rapidly expanding Ottoman Empire in the east and were pushed back. Infighting Christian infighting Clashes and raids on bordering Andalusian lands did not keep the Christian kingdoms from battling among themselves or allying with Muslim kings. Some Muslim kings had Christian-born wives or mothers. Some Christian mercenaries, like El Cid, were contracted by taifa kings to fight against their neighbours. Indeed, El Cid's first battle experience was gained fighting for a Muslim state against a Christian state. At the Battle of Graus in 1063, he and other Castilians fought on the side of al-Muqtadir, Muslim sultan of Zaragoza, against the forces of Ramiro I of Aragon.