Morocco–Spain border

The Morocco–Spain land border consists of three non-contiguous lines totalling 18.5 km (11.5 miles) around the Spanish territories of Ceuta (8 km; 5 miles), Peñón de Vélez de la Gomera (75 metres; 80 yards) and Melilla (10.5 km; 6½ miles). Spanish islets such as the Chafarinas or the Alhucemas are located off the Moroccan coast.

History
Historically the plazas de soberanía were part of various Muslim empires of north-west Africa. Ceuta was conquered by Portugal in 1415. Following the Reconquista of the Iberian peninsula, Spain looked south to the North African coast, capturing Melilla from the Sultanate of Fez in 1497, with Portugal's blessing. Spain took the then-island of Peñón de Vélez de la Gomera by force in 1508, with Portugal recognising this claim the following year with the Treaty of Cintra. Retaken by the Kingdom of Fez in 1554, Spain reconquered it in 1564, and it has remained in Spanish hands since that time.

During the period of Iberian Union (1580-1640) Ceuta attracted many Spanish settlers; as a result, when Portugal regained its independence from Spain in 1640 Ceuta opted to remain with Spain, a situation Portugal acquiesced to in 1688 with the Treaty of Lisbon. A treaty outlining Ceuta's boundary with Morocco was signed 7 October 1844 and confirmed by another on 6 May 1845. A treaty outlining the Melilla-Morocco boundary, replete with a parallel ‘neutral zone’, was signed 24 August 1859.

Repeated Moroccan attempts to gain control of the two exclaves by force during the 18th-19th centuries failed, culminating in the Hispano–Moroccan War of 1859–60, which resulted in a Spanish victory. The subsequent Treaty of Wad-Ras (aka the Treaty of Tétouan) of 26 April 1860 expanded the border of Ceuta to its present limit. Melilla's border was supposed to be fixed by 'the range of a piece of cannon', however this proved impractical, and a further treaty was therefore signed on 30 October 1861 and confirmed on 26 June 1862 which outlined the modern boundary line. Localised disputes in Melilla continued however, and further treaties were signed in 1894–95.

By a Franco-Spanish treaty of 27 November 1912, Spain was granted a protectorate over Morocco's Mediterranean littoral, referred to as Spanish Morocco. Ceuta, Peñón de Vélez de la Gomera and Melilla thereafter were absorbed into this entity. When Morocco gained independence from France in 1956, Spanish Morocco was handed to the new kingdom. However, Spain maintained control of the plazas de soberanía, asserting that they were Spanish territory long before the creation of the protectorate in 1912 and should therefore remain part of Spain, a position contested by Morocco.

In 1934 a huge storm created a tombolo between Peñón de Vélez de la Gomera and the Moroccan mainland, effectively making the former island a new Spanish exclave on the coast of Morocco. A formal border treaty was never signed between Morocco and Spain regarding the newly-formed exclave, and a short 75-metre (80 yard) straight line throughout the sandy spit connecting it to Morocco has functioned as a de facto frontier since that time.

Since Moroccan independence the dispute over the plazas de soberanía has flared up from time-to-time, most notably in 1975 when it was feared Morocco would attempt an invasion of the territories similar to the Green March invasion of Western Sahara conducted that same year. At present Spain remains in control of the plazas and refuses to discuss the issue of their sovereignty with Morocco.

In 1993 Spain began building the Ceuta and Melilla border fence, which were further strengthened in 1995. In response to an increase in the number of migrants attempts to breach the fence, both were significantly fortified in 2005, creating a doubled-fence system replete with barbed wire and surveillance equipment. Since then there have been numerous attempts to cross the fences, resulting in several fatalities. On 17 May 2021, more than 6,000 migrants crossed the border into Ceuta. It was widely speculated that Morocco permitted the sudden influx to punish Spain for allowing Polisario Front leader Brahim Ghali to be treated at a Spanish hospital. The next day, Morocco closed the border again. Most of the arrivals returned to Morocco.

Maritime borders
Morocco and Spain also share a maritime border in the Canary Islands area and along the Strait of Gibraltar and the Alboran Sea. The shortest distance between land along the Strait of Gibraltar is 14.3 km. The British territory of Gibraltar is located on the northern coast of this strait.