The city was founded in 1471 as a small "kasbah" (fortress) by Moulay Ali ibn Rashid al-Alami, a descendant of Abd as-Salam al-Alami and Idris I, and through them, of the Islamic prophet Muhammad. Al-Alami founded the city to fight the Portuguese invasions of northern Morocco. Along with the Ghomara tribes of the region, many Moriscos and Jews settled here after the Spanish Reconquista in medieval times. After eight years of the creation of the Spanish Protectorate in Morocco the Spanish Army could effectively take Chaouen, when General Dámaso Berenguer occupied the city on 14 October 1920.