Of all the African nations the closest to Europe, Morocco always was the target of European expansion. As early as 1253, Genoa acquired Safi in Morocco.
During 1331-51, Abu al-Hasan 'Ali reigned in Morocco. He conquered Tlemcen (Algeria) in 1337 and even managed to extend Morocco's rule to Tunisia in 1347-57. Later, his empire would fall apart again, though.
But the fate of Morocco was sealed in 1430: To get rid of the mighty nobles in Castille, king Pedro III told them to go on a crusade to Morocco, which was subjugated during the next 20 years. The country was redivided into fiefs of the mighty families, and the Castillians did everything to rechristianize it. After the Castillian conquest, some Moroccans started to flee South, to Mauretania or even Timbuktu.
Under Castillian rule
The Castillians mostly fought the (until then) ruling Arabs, leaving the Berbs somewhat alone and even tolerated the Jews (who were evicted from Castille proper).
During the Great Occidental War, during 1538-42 uprisings happened in Morocco. The rebelling Muslims were enslaved and mostly brought to the New World. However, their fight distracted the Quadruple Monarchy, which had to move Castillian troops from France to Morocco. Now many Moroccan warriors fled to Songhay, introducing gunpowder weapons to this country.
The 1580s saw the biggest uprisings in Morocco and Algeria yet, but these were defeated too.
Under the Monteleóns
Of the noble families settled in Morocco, the Monteleóns were the most powerful and influential ones. After the Triple Monarchy of England-Castille-Portugal fell apart in 1628, and the Castillian Civil War}} broke out, the Cortes (parliament) of Morocco elected duke Francisco of Monteleón the new king. 1636-39, Castille (now named Spain) tried to conquer Morocco back, unsuccessfully.
In 1639 however, Maria, the princess of Spain and future queen (her father Alfonso XII had no son) married Francisco of Monteleón, thus reuniting their realms again. 1665, she appointed her younger, but more competent son Héctor I successor, sent her older son Francisco as governor to Morocco.
1793, after Spain had lost the third French Republican War, the Spanish royal family went to Morocco. Many Spanish refugees followed during the next decades, finally giving Morocco a Christian majority. With help from Britain, they still supported uprisings in Iberia (thus keeping the "Ninety-Year War" alive). However, Morocco itself suffered great losses of men and money too, and after a last Muslim uprising Morocco was conquered by New Rome during 1838-40. The Monteleóns were interned.