The History of Fez begins with its foundation by Idris I and Idris II at the end of the 8th century and the beginning of the 9th century CE. It initially consisted of two autonomous and competing settlements on opposing shores of what is now known as the Oued Fes. Initially inhabited by a largely Berber (Amazigh) population, successive waves of mainly Arab immigrants from Ifriqiya (Tunisia) and al-Andalus (Spain/Portugal) over time gave the nascent city an Arab character as well. After the downfall of the Idrisid dynasty, it was contested between different Zenata groups allied with either the Fatimid Caliphate or the Umayyad Caliphate of Cordoba. In the 11th century the Almoravid sultan Yusuf ibn Tashfin conquered the region and united its two settlements into what is today the Fes el-Bali