The History of Morocco spans over 12 centuries, without considering the Classical antiquity. The country was first unified by the Idrisid dynasty in 780, representing the first Islamic state in Africa autonomous from the Arab Empire. Under the Almoravid dynasty and the Almohad dynasty, Morocco dominated the Maghreb and Muslim Spain. The Reconquista ended Almohad rule in Iberia and many Muslims and Jews migrated to Morocco. Under the Saadi dynasty, Morocco would consolidate power and fight off Portuguese and Ottoman invaders, as in the battle of Ksar el Kebir. The reign of Ahmad al-Mansur brought new wealth and prestige to the Sultanate, and an invasion of the Songhay Empire was initiated. However managing the territories across the Sahara proved to be difficult. After the death of al-Mansur the country was divided among his sons. In 1666 the sultanate was reunited by the Alaouite dynasty, who have since been the ruling house of Morocco. The organization of the state developed with Ismail Ibn Sharif. With his Black Guard he drove the English from Tangier (1684) and the Spanish from Larache (1689). The Alaouite dynasty distinguished itself in the 20th century by maintaining Moroccan independence while other states in the region succumbed to European interests. In 1912, after the First Moroccan Crisis and the Agadir Crisis, the Treaty of Fez was signed, effectively dividing Morocco into a French and Spanish protectorate. In 1956, after 44 years of occupation Morocco regained independence from France as the Kingdom of Morocco.