The final curtain on the Muslim presence on the Iberian Peninsula came down on January 2, 1492, when the last Muslim ruler of Granada, the Nasirid Sultan Abu Abdullah Muhammad XII (“Boabdil” to the Spaniards, for whom “Abu Abdullah” was apparently too hard to pronounce), went into exile in Morocco. But the departure was a formality. Boabdil was obliged to leave by the Treaty of Granada, which he signed, along with the victorious King Ferdinand (d. 1516) and Queen Isabella (d. 1504), on November 25, 1491.
The Treaty of Granada ended the Granada War (go figure), which started in 1482 after an incredibly ill-advised Granadan attack on the Castilian city of Zahara, ordered by the reigning Sultan, Boabdil’s father Abu al-Hasan Ali. The Granadans took Zahara, but it was a Pyrrhic victory if ever there was one. Isabella had only just won out in the struggle to succeed her brother, Henry IV (d. 1474), as ruler of Castile, which meant that the two largest proto-Spanish kingdoms were now united by virtue of her marriage to Ferdinand of Aragon, and that was bad news for the Granadans. Not only was the combined army much stronger than the Granadan army, but the combined kingdom also had the resources to bring in artillery experts to design and craft plenty of siege guns.
Also bad news for the Granadans was the fact that Boabdil decided to revolt against his father and declare himself Sultan. Shortly after he began his rebellion, Boabdil was captured and then released, and even supported, by Ferdinand and Isabella, put in play to throw the Granadans into civil war. By 1487, Boabdil was ruler of Granada, which probably would not have been possible without the support of the Spanish monarchs. But if he was expecting his former backers to let him rule in peace as their vassal, he was in for a real shock when they started gobbling up his territory instead. He sent for aid from Muslim rulers in Fez and Egypt, but the most he got was a strongly worded “cut the crap” letter from the Egyptian Mamluk Sultan Qaitbay to Ferdinand, which shockingly had no effect.
Ferdinand and Isabella’s combined army besieged Granada in April 1491, and the surrender of the city was by this point a foregone conclusion. The treaty is actually a marvel of religious tolerance, one that would be completely discarded in the insane forced conversion/expulsion/Spanish Inquisition period that was to follow over the next couple of centuries. It stipulated that Muslims in Granada should keep their property and places/freedom of worship if they chose to stay, and allowed them safe passage to North Africa if they chose to leave; that they should be governed according to Islamic law and not forced to convert to Christianity; and even that they should be exempt from taxation for some interim period of time. Boabdil went off into exile in Fez, where he lived until his death in 1533.
The protections contained in the treaty remained in place for, I don’t know, like a couple of weeks or something–by 1499, a scant 8 years later, Muslims living in Granada felt mistreated enough to revolt. Their uprising was quickly put down, but it was used as an excuse for Ferdinand and Isabella to tear up the Treaty of Granada and institute a policy of forced conversion or expulsion. Frankly, the Muslims got off easy; Jews were given the “convert or GTFO” choice in the Alhambra Decree of 1492, because…well, because they were Jews, let’s be honest. Medieval Christians rarely needed a reason to do terrible things to European Jews. By the second half of the 16th century, conditions even for the Moriscos, the Christian descendants of former Muslims who had converted to Christianity (and who were as thoroughly Spanish as anyone else living there), were deteriorating fast, and many of them were expelled from Spain (at their own expense, no less) starting in 1609.