The city was founded in 1471 as a small kasbah by Ali ibn Rashid al-Alami, a descendant of Abd al-Salam ibn Mashish al-Alami and Idris I. Al-Alami built the kasbah to defend against Portuguese invasions of northern Morocco. Along with the Ghomaras of the region, many Moriscos and Spanish and Portuguese Jews settled here during and after the Reconquista of Spain. Ali Ben Rashid was born in Gherzoim, a nearby village, c. 1440 (844 AH). He went to Emirate of Granada in 1460 and achieved outstanding services in battle against the Crusaders. He settled in Chefchaouen c. 1465 and, due to his experience as a warrior, was chosen as successor to his cousin ibn Abi Jum'ah and leader of the Mujahideen in the northwest of Morocco. He fought alongside the Amir of Tétouan, Ali al-Mandri, who married his daughter, the Mujahida Aisha al-Hurra. The latter, known by her title, Sayyida al-Hurra, reigned Chefchaouen through a rapid period of growth and development. Chefchaouen was home to Andalusian families between 1492 and 1609, when the last Moriscos were expelled from Andalusia by King Felipe III. These Andalusian families built their own residential quarters surrounded by walls, in the Andalusian architectural style, very similar to the Arab quarters of Granada.