Morocco, officially the Kingdom of Morocco, is a country located in the Maghreb region of North Africa. It overlooks the Mediterranean Sea to the north and the Atlantic Ocean to the west, with land border with Algeria to the east and Western Sahara to the south. Morocco also claims the exclaves of Ceuta, Melilla and Peñón de Vélez de la Gomera, all of them under Spanish jurisdiction, as well as several small Spanish-controlled islands off its coast. The capital is Rabat and the largest city is Casablanca. Morocco spans an area of 710,850 km² and has a population of over 36 million.
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 under Almoravid and Almohad rule, when it spanned parts of Iberia and northwestern Africa. The Portuguese Empire began in Morocco in the 15th century, following Portuguese conquests along the Moroccan coast, founding settlements which lasted into the 17th and 18th centuries. The Marinid and Saadi dynasties resisted foreign domination into the 17th century, allowing Morocco to remain the only northwest African country to avoid Ottoman occupation.