Morocco's internationally recognised land borders touch three neighbours: Algeria to the east, along 1,559 km; Spain, along three short lines totalling 18.5 km around Ceuta, Melilla and the Peñón de Vélez de la Gomera; and Western Sahara to the south, along a 444 km line. Together those come to roughly 2,020 km. In practice the map looks different, because Morocco claims Western Sahara and controls about 70% of it, so the country its traffic actually meets in the south is Mauritania, at the Guerguerat crossing. At sea, Morocco faces mainland Spain across the 14.3 km Strait of Gibraltar, Spain's Canary Islands off its Atlantic coast, and Algeria along the Mediterranean, with Portugal's Madeira further north. All figures here come from Wikipedia's articles on each border, and the land lines come first.
Algeria: 1,559 km from the Mediterranean to the Draa, closed since 1994
The Algerian border starts on the Mediterranean just west of the Algerian village of Marsa Ben M'Hidi and runs south past Oujda and Ahfir on the Moroccan side and Maghnia on the Algerian side. Near the oasis of Figuig it swings sharply west, then heads south-west, follows the Draa River for a stretch, and ends with a straight 116 km run due south to the Western Sahara tripoint. Figuig, Merzouga and M'Hamid El Ghizlane, a small oasis town of about 7,500 people in Zagora Province, are among the Moroccan settlements closest to it.
The northern part dates from the Treaty of Lalla Marnia of 18 March 1845, signed after France occupied coastal Algeria, which fixed the line from the sea to Teniet el-Sassi. Protocols in 1901 and 1902 pushed it south to Figuig, but everything beyond was left vague. That vagueness, together with Morocco's post-independence claim to a "Greater Morocco" reaching into the Tindouf and Béchar regions, led to the Sand War of 25 September to 30 October 1963. Moroccan troops occupied the border posts of Hassi Beida and Tindjoub and pushed towards Tindouf before a truce was agreed at Bamako, in Mali, on 30 October, with Ethiopia's Haile Selassie and Mali's Modibo Keïta mediating; the Organisation of African Unity then mediated a formal peace treaty, signed on 20 February 1964. A treaty of 15 June 1972 demarcated the whole border for the first time; Algeria ratified it in 1973, Morocco only in 1992.
The frontier has been shut since 1994. After an attack in Marrakesh that year killed two Spaniards, Morocco blamed Algerian intelligence and imposed visas on Algerians, and Algeria responded by closing the border. Trade and travel between the two are still legal, but only by air or sea, and the closure has been estimated to cost each country about 2% of annual growth. Smugglers, especially of drugs, still cross the line on foot. Relations worsened over Western Sahara, where Algeria hosts the Polisario Front and Sahrawi refugees around Tindouf. On 24 August 2021 Algeria cut diplomatic ties, a month later it closed its airspace to Moroccan aircraft, and on 31 October 2021 it let the contract for the Maghreb–Europe gas pipeline across Morocco expire.
Ceuta, Melilla and the 85-metre Peñón de Vélez line with Spain
Spain is Morocco's only European land neighbour, and the two share three separate stretches of frontier: 8 km around Ceuta, 10.5 km around Melilla, and just 85 m at the Peñón de Vélez de la Gomera. The Peñón was an island until a storm in the 1930s (sources give 1930 or 1934) built a sand spit linking it to the Moroccan shore, which gave it one of the shortest international land borders in the world.
These lines are older than Morocco's modern borders. Portugal captured Ceuta in 1415, and the city chose to stay with Spain when Portugal regained independence in 1640, a choice Portugal accepted in the Treaty of Lisbon of 1668. Spain took Melilla in 1497 and the Peñón in 1508, lost the rock to Moroccan attackers in 1522 and held it again from 1564. The Hispano-Moroccan War of 1859–60 ended with the Treaty of Wad-Ras of 26 April 1860, which pushed Ceuta's boundary out to its present limit; Melilla's was supposed to be set by the range of a cannon shot, and when that proved unworkable a treaty of 1861 drew the modern line.
Morocco has claimed the enclaves since independence in 1956, and Spain refuses to discuss their sovereignty. Because both cities are part of the European Union, they and the Peñón form the only land borders between the EU and an African country. The enclaves were never part of the Spanish protectorate that ruled Morocco's northern coast from 1912, so when Spain gave up that protectorate in the Hispano-Moroccan Joint Declaration of 7 April 1956, it kept them. Spain began fencing them in 1993 and turned both into double fences with barbed wire and sensors in 2005; at Ceuta the parallel fences stand 6 m high. In September 2005 thousands of migrants tried to climb the Melilla fences in waves; about 700 got over and six died. On 17 May 2021 more than 6,000 migrants entered Ceuta in a day, and on 24 June 2022 at least 23 people died in a crush at the Melilla fence.
Western Sahara: the 444 km line along latitude 27°40′N
Morocco's recognised southern border is a single straight line along the parallel of 27°40′N, running 444 km from the Atlantic coast to the Algerian tripoint through thinly populated desert. France and Spain drew it in a treaty of 3 October 1904, when the land south of it became the Spanish colony of Saguia el-Hamra.
Since 1976–79 the line has existed only on paper. Western Sahara covers about 272,000 km², has an estimated 600,000 inhabitants and is listed by the United Nations as a non-self-governing territory. Spain tried to hand its administration to Morocco and Mauritania in 1975–76, although an advisory opinion of the International Court of Justice had found that neither held sovereignty over it; Mauritania gave up its claim in 1979, and Morocco took over that share as well. The Polisario Front, backed by Algeria, proclaimed the Sahrawi Arab Democratic Republic, which is a member of the African Union. A UN-brokered ceasefire in 1991 promised a referendum that has never been held. Today Morocco controls about 70% of the territory, including all its main towns, and calls it its Southern Provinces; the Polisario Front holds the rest. A sand berm some 2,700 km long, lined with landmines, separates the two zones. In 2025 the UN Security Council endorsed negotiations based on Morocco's autonomy proposal, while the territory's final status remains unresolved. Our Western Sahara guide covers the territory itself.
Mauritania at Guerguerat: the de facto southern neighbour
Because Morocco administers the Atlantic side of Western Sahara, its road south ends at the Mauritanian frontier, a 1,564 km boundary first drawn by France and Spain on 27 June 1900. It is a line of surveyors' segments: south along a straight line from the Algerian tripoint, west along the 26th parallel for 334 km, south along the 12th meridian for 176 km, then west along latitude 21°20′N for 408 km before it bisects the Ras Nouadhibou peninsula to reach the sea. The crossing is at Guerguerat, about 11 km from the border and 5 km from the ocean, on what is often described as the only safe road from North Africa to sub-Saharan Africa, because the Sahel countries further east face serious security problems. Moroccan vegetables bound for Nouadhibou and the rest of Mauritania pass through it.
Guerguerat matters to both sides of the Western Sahara dispute. On 13 November 2020 Moroccan forces moved into the area to restore free movement of goods and people on the road, and the Polisario Front declared the 1991 ceasefire over, while Morocco said the truce remained in place. Morocco has since opened a mosque (March 2023) and a seawater desalination plant (November 2023) at Guerguerat, and its football federation announced two pitches there and at Bir Gandouz.
Across the Strait of Gibraltar: Perejil, the Alboran Sea and the Canaries
Morocco is one of only three countries, with Spain and France, that have both an Atlantic and a Mediterranean coastline, so it has sea neighbours on two fronts. The main one is Spain. At its narrowest the Strait of Gibraltar is 14.3 km wide, the gap that separates Africa from Europe and keeps alive the question of whether Morocco belongs to Africa or Europe. Territorial waters in the strait follow the median line, and international shipping has unimpeded transit passage, as described in our Strait of Gibraltar guide.
Spain also holds small islands just off the Moroccan coast: the Chafarinas islands, the Peñón de Alhucemas and Perejil, a rocky islet only 250 m from the shore whose sovereignty Morocco disputes and which it calls Tura. It lies about 8 km from Ceuta and 13.5 km from mainland Spain, and local Moroccan shepherds have used it for grazing. Moroccan troops landed on Perejil on 11 July 2002, and on 18 July Spanish special forces retook it without resistance from the Moroccan cadets on the islet. Further east, Spain and Morocco have never agreed a full maritime boundary in the Alboran Sea, and beyond the land border's northern end Morocco's waters meet Algeria's.
In the Atlantic, the nearest of the Canary Islands, Fuerteventura, lies about 96 km from Cape Juby. That is wider than the 24 nautical miles of two territorial seas, so those waters never meet, but the two countries' exclusive economic zones overlap and no boundary between them has been signed.
