Chefchaouen is situated in the Rif Mountains, just inland from Tangier and Tetouan. The city was founded in 1471,as a small fortress which still exists to this day, by Moulay Ali Ben Moussa Ben Rached El Alami (a decendent of Ibn Machich and Idris I, and through them, of the prophet Muhammad) 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.In 1920, the Spanish seized Chefchaouen to form part of Spanish Morocco. Spanish troops imprisoned Abd el-Krim in the kasbah from 1916 to 1917, after he talked with the German consul Dr. Walter Zechlin (1879–1962). (After defeating him with the help of the French force Abd el-Krim was deported to Réunion in 1926). Spain returned the city after the independence of Morocco in 1956.