Rail transport in Morocco was initially developed in the colonial era. It functioned primarily as a means to mobilize colonial troops and to transport natural resources. Later, a standard-gauge network was built.
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.
The first French-built narrow-gauge railway line in French 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.