The Islamic Moors had invaded and conquered the Iberian peninsula in 711-718. While the Moors occupied most of Spain, the city of Grenada became one of the largest Muslim kingdoms of that time. Christians and Jews were forced to live under restrictions imposed by the ruling Muslims. Islamic leaders became stricter as decades went by, invading churches and forbidding public displays of faith, per BBC.
The 1238 Christian Reconquest then drove Muslims living in Northern Spain South and Grenada was established as the last refuge of the Islamic Moors.
200 years passed before the Moors began to struggle internally for power in the late 15th century. At the same time, the Spanish monarchy was strengthened by Christian leaders Ferdinand and Isabella. On January 2, 1492, King Boabdil who ruled the Moors at the time, surrendered Granada to the Spanish forces, ending the presence of any Islamic community in Spain. In 1502 the Spanish crown told Muslims remaining in Spain that they would need to either convert to Christianity or leave.
By 1609 the last Islamic Moors were expelled from Spain completely.