Since the foundation of the first Moroccan state by Idris I in 788 AD, the country has been ruled by a series of independent dynasties, reaching its zenith in the 11th and 12th centuries under the Almoravid and Almohad dynasties, when it encompassed parts of Iberia as well as part of northwestern Africa. Beginning in the 15th century, the Portuguese Empire extended to include parts of Morocco: Portugal conquered territory along the Moroccan coast and founded settlements some of which endured into the 18th century. Nevertheless, the Moroccan dynasties of Marinid (which ruled from the 13th into the 15th century) and Saadi (which ruled from the 15th into the 17th century) otherwise resisted foreign domination: Morocco was the only country in northwest African to escape occupation by the Ottoman Empire. The Alaouite dynasty, which rules Morocco to this day, seized power in 1631. The country's strategic location near the mouth of the Mediterranean eventually attracted the interest of European powers: In 1912, Morocco was divided into French and Spanish protectorates, with an international zone in Tangier. It regained its independence and reunified in 1956, and has been relatively stable and prosperous (by regional standards) since then: Today, it has the fifth largest economy in all of Africa.