Spanish Protectorate in Morocco The Spanish protectorate in Morocco ( " Himayat Isbaniya fi Al - Maghrib " ; ) arose as a result of the Agadir crisis and was established on the basis of the Treaty of Fez in March 1912 ( in which Sultan Abdelhafid allowed Germany to cede protection of Morocco to France and Spain ) which defined it ( Art . I Par . 3 ) as a Spanish sphere of influence in the French Protectorate of Morocco . It was formally defined as a Spanish Protectorate nine months later as a result of a subsequent " Treaty between France and Spain regarding Morocco " signed in Madrid 27 November 1912 . It ended in 1956 , when both France and Spain recognized Moroccan independence . Territorial borders . Initially , a Spanish zone of influence in Morocco was established in 1912 , consisting of the northern part of the country and the Cape Juby Strip . While the sparsely populated Cabo Juby was administered as a single entity with Spanish Sahara , the northern territories of the Spanish zone of influence , consisting of the northern part of Morocco , except Ceuta , Melilla and Tangier , were administered as a protectorate with its capital at " Tetuán " ( Tétouan ) . Spanish troops provisionally occupied Tangier during World War II , on the pretext that an Italian invasion was imminent . The Republic of the Rif led by the guerrilla leader Abd El - Krim was a breakaway state that existed in the Rif region from 1921 to 1926 , when it was dissolved by joint expedition of the Spanish Army of Africa and French forces during the Rif War . Spanish enclaves in northern Morocco . The Protectorate did not formally include Ceuta and Melilla . As for the " plazas de soberanía " ( Spanish name for various enclaves and islands on the northern Moroccan coast ) , they were gained in 16th – 19th centuries , before the international agreements on the Protectorate . History . The Protectorate system was established in 1912 . The legal Islamic qadi s system was formally maintained . The Moroccan Sephardi Jews — many of them living in this part of the Maghreb after being expelled from Spain and Portugal in 1492 and 1497 respectively after the end of the Reconquista process — flourished in commerce , profiting from the similarity of Spanish and Ladino language and benefiting from the tax - exempt area in Tangier and a flourishing trading activity in the area . The Spanish Civil War started in 1936 with the uprising of the Spanish troops stationed in " África " ( as the Protectorate was informally known in the Spanish military parlance ) under the command of Francisco Franco against the Republican Government . These troops became the core of the Nationalist Army , which also recruited a considerable number of Moroccan troops . The communist parties , the Communist Party of Spain and Workers ' Party of Marxist Unification ( POUM ) , advocated anti - colonialist policies whereby the Republican Government would support the independence of Spanish Morocco , intending to create a rebellion in Franco ' s back and cause disaffection among his Moroccan troops . However , the Republican Government under the Spanish Socialist Workers ' Party ( PSOE ) rejected any such idea - which would have likely resulted in conflict with France , the colonial ruler of the other portion of Morocco . Because the local Muslim troops had been among Franco ' s earliest supporters , the protectorate enjoyed more political freedom than Franco - era Spain proper after Franco ' s victory , with competing political parties and a Moroccan nationalist press , criticizing the Spanish government . In 1956 , when French Morocco became independent , Spain discontinued the Protectorate and surrendered the territory to the newly independent kingdom while retaining the " plazas de soberanía " , Ifni and other colonies outside Morocco , such as Spanish Sahara . Unwilling to accept this , the Moroccan Army of Liberation waged war against the Spanish forces and in the Ifni War of 1958 , spreading from Sidi Ifni to Rio de Oro , gained Tarfaya . In 1969 , Morocco obtained Ifni . Morocco claims Ceuta and Melilla as integral parts of the country , considering them to be under foreign occupation , comparing their status to that of Gibraltar . Economy . The iron mines in the Rif were one of the sources of income . Its exploitation led to an economic boom in Melilla . Transport . The Junta de Obras del Puerto de Melilla started at ones extensive building of harbour to carry mineral traffic overseas , mainly to Spain . With new harbour installations the company built also a 750 mm gauge local 4 . 1 km harbour line from Melilla Harbour to Sidi Musa , later extended to the total length of 7 km as demanded by Spanish military . The Junta de Obras and the Compañía Transatlántica Española were merged to form a new company , the Junta de Fomento de Melilla on 16 December 1911 . The Compañía Española de Minas del Rif was founded on 21 July 1908 . It had obtained mining rights at Idem , Beni Sidel and Mazuza areas . The company built an extensive railway network in the Melilla area . The 1000 mm gauge main line Melilla - Beni Ensar - Tizi Tavessart - Atalayon - Nador - Segagnan - San Juan de las Minas - Minas de Jebel Uisai ( Ulad Canem ) 31 , 5 km was the first common carrier railway in Spanish Morocco between Melilla and San Juan de las Minas . In spring 1914 the Compañía Española de Minas del Rif operated three daily passenger trains to Nador of which two continued to San Juan de las Minas with corresponding return workings to Melilla . Another company , the Ferrocarril Nador - Tistutin built a 1000 mm gauge 36 km Nador - Tinequemart - Zeluan - Monte Arruit - Tistutin - El Batel line . There was continuous unrest in the area and the Rif Cabyle rebels attacked the railways . The Spanish Army concentrated nearly 100 . 000 soldiers to pacify the Rif area and built an extension westward from El Batel . At first El Batel - Dar Driuch - Laababda - Zoco el Had , El Batel - El Aasel - Dar Mohan - Ulad Candusi , Dar Driuch - Ben Tiep and Laababda - Dar Tafersit lines were operated by locotractors which could haul 200 tons with three locotractors . Later , when El Batel - Dar Driuch 23 . 5 km , El Batel - Ulad Candussi - Dar Quebdani 23 km , Dar Driuch - Tafersit 12 km had been decided to be built to standard 600 mm gauge field railways the Spanish Army bought a number of surplus former German built World War I locomotives and rolling stock from Germany . When the area was finally pacified in 1926 the lines were lifted and the rolling stock transferred elsewhere . There were also two other companies which operated their own mining railways . The Compañía del Norte Africano and the Compañía Minera Setolazar , both of 600 mm gauge . Both companies had common locomotive shed at Beni Ensar . Their 600 mm gauge line run parallel with Compañía Española de Minas del Rif 1000 mm gauge line between Nador and Melilla Harbour . The Ferrocarril Ceuta - Tetuán was founded on 15 September 1912 to connect Ceuta to Tetuán with 41 km 1000 mm gauge railway . The line was opened on 17 Marc 1918 . Ferrocarril Ceuta - Tetuan built stations at Ceuta ( 0 . 5 km ) , Miramar , Ceuta ( 2 . 9 km ) , Castillejos ( 8 . 0 km ) , Dar Riffen ( 11 . 1 km ) , Negro ( 13 . 8 km ) , Rincón del Medik ( 24 . 9 km ) , Malalien ( 38 . 1 km ) , and terminal station Tetuán ( 41 . 0 km ) . When Spanish General Alfau occupied Tetuán in 1913 it was decided to build an 18 km 600 mm gauge railway to Río Martín using the trackbed of the former lifted standard gauge railway . The 10 km Ferrocarril Tetuan - Rio Martin y prolongaciones was opened on 20 May 1915 for public service . The extensions south to Benkarrir and Zina 18 km was opened on 31 . 03 . 1921 and west to Laucien 8 km , when the railway bridge at Mogote was finally completed , on the same day . The Austrian company Sager & Wörner had obtained from the Spanish Government the contract to build the harbour installations at Larache on the Atlantic coast in 1911 . The harbour was built in 1911 - 1914 but World War I delayed the 34 km standard gauge railway line to Larache to 1922 . Compañía del Norte Africano 600 mm gauge industrial railway served the lead mines at Monte Afra with company ' s Melilla - Nador - Monte Afra line on the north coast . The length of this lead carrier was 19 km .