First 600 mm (1 ft 11 5⁄8 in) line
The first short narrow-gauge railway in Morocco was a 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 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.
The first French-built narrow-gauge railway line in Morocco was completed in 1908 with minimum-gauge track, which was later converted to narrow-gauge track. More lines utilizing gauge track followed. Beginning in 1912 and ending in 1935, French Morocco had one of the largest 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 standard-gauge railway in Morocco until the standard-gauge Tangier - Fes Railway being completed, the French begun to build military 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.
There have been narrow-gauge railways which used meter gauge, gauge, and gauge in former Spanish Morocco. A narrow-gauge railway was also constructed from Tetuan to Ceuta in 1913–1918 by CEC. It was handed over to the state-run FCM in 1942 and closed in the aftermath of the Moroccan independence.
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 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 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 built the Oujda - Bouarfa, Morocco railway which was completed in 1927.
The Mediterranean-Niger-Railway 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.