# History of rail transport in Morocco

Rail transport in Morocco was initially developed during the protectorate. It functioned primarily as a means to mobilize colonial troops and to transport natural resources. Later, a standard-gauge network was built.

## First narrow-gauge lines
### First 600 mm (1 ft 11 5⁄8 in) line

The first short narrow-gauge railway in Morocco was a 600 mm (1 ft 11+5⁄8 in) narrow-gauge line presented to the Sultan of Morocco in 1887 by the Belgian Government to connect his palace with his Jardin l'Agdal de Meknes. With the railway came two coaches and one steam locomotive (Krauss 1744 / 1887 Ct-n2 ) delivered via F. Weidknecht, Paris. This move was done to improve the Belgian trade possibilities with the Sultan with hope to build railways in Morocco.

### Narrow-gauge railways in former French Morocco

In 1907, the French Compagnie Marocaine established a 600 mm (1 ft 11+5⁄8 in) line connecting the Port of Casablanca to a quarry in Roches Noires with a Decauville engine, though it was destroyed by tribesmen of the Shawiya.
The first major French-built narrow-gauge railway line in Morocco was completed in 1908 with 500 mm (19+3⁄4 in) minimum-gauge track, which was later converted to 600 mm (1 ft 11+5⁄8 in) narrow-gauge track. More lines utilizing 600 mm (1 ft 11+5⁄8 in) gauge track followed. Beginning in 1912 and ending in 1935, French Morocco had one of the largest 600 mm (1 ft 11+5⁄8 in) gauge networks in Africa with a total length of more than 1700 kilometres. After the treaty of Algeciras where the representatives of Great Powers agreed not to build any 1,435 mm (4 ft 8+1⁄2 in) standard-gauge railway in Morocco until the standard-gauge Tangier - Fes Railway being completed, the French begun to build military 600 mm (1 ft 11+5⁄8 in) gauge lines in their part of Morocco.
The 948 km Marrakech - Casablanca - Kenitra - Fes - Oujda line became known as Chemins de fer strategiques du Maroc and the branch lines diverting from the line as Chemins de fer de penetration du Maroc. These lines were mostly built - with exception of Guercif - Outat Oulad el Hadj - Midelt, which was started in 1916 and completed in 1920 - during the period of 1921 - 1925.

## Railways in former Spanish Morocco

There have been narrow-gauge railways which used meter gauge, 1,000 mm (3 ft 3+3⁄8 in) gauge, and 600 mm (1 ft 11+5⁄8 in) gauge in former Spanish Morocco.
A narrow-gauge railway was also constructed from Tetuan to Ceuta in 1913–1918 by CEC (Compañía Española de Colonización). It was handed over to the state-run FCM (Ferrocarrilles de Marruecos) in 1942 and closed in the aftermath of the Moroccan independence (1956).

## Standard-gauge railways

Before the independence of Morocco in 1956 four standard-gauge railways were built by individual companies. In 1963 all four were merged to form the ONCF, Morocco's current national railway operator.

### Railways of Morocco

Railways of Morocco (French Compagnie des chemins de fer du Maroc (CFM) ) was established in 1920 and built two railway lines:
* Casablanca to Kenitra and Sidi Kacem, completed in 1925
* Casablanca to Marrakech railway, completed in 1936.

### Franco-Spanish company of Tanger-Fès

From 1919 the Franco-Spanish company of Tanger-Fès (French: Compagnie Franco-espagnole du Tanger-Fès (TF) ) started construction of the 315 km Tangier - Fes railway, out of which 18 km were in the International zone of Tangier, 93 km in the Spanish zone and 204 km in the French zone. The railway was finished in 1927.

### Railway of Eastern Morocco

Railway of Eastern Morocco (French: Compagnie du chemin de fer du Maroc oriental (CMO) ) built the Oujda - Bouarfa, Morocco railway which was completed in 1927.

### Mediterranean-Niger-Railway

The Mediterranean-Niger-Railway (French: Chemins de Fer de la Méditerranée au Niger (MN) ) was built between the coal mining region near Bou Arfa in the east of Morocco and the Algerian rail system at Oujda, completed as standard-gauge route between Oran and Oujda in 1922, while Fes was reached in 1934.