Uyuni was founded in 1890 as a railway centre - it was an important junction where the lines from the nearby mine at Huanchaca to Antofagasta (an important port on the coast) and La Paz to Villazon on the Argentina border crossed. The railway began life with a concession granted by the Bolivian government to Melbourne Clarke & Co and was organised as the Antofagasta Nitrate & Railway Company. The War of the Pacific (which saw Bolivia's Litoral Province which included Antofagasta become part of Chile) interrupted construction work from the coast to the interior; after the war control of the railway passed to the Huanchaca of Bolivia Company in 1887. The railway was subsequently floated on the London stock exchange in 1888 as the Antofagasta and Bolivia Railroad Company (Ferrocarril de Antofagasta a Bolivia in Spanish or FCAB). With significant British capital and engineering expertise the lines reached Oruro in 1892 and La Paz by 1913. The company also built other lines in the north of Chile.
The railway began to replace its steam locomotives with diesel ones in 1958 and in 1964 the Bolivian government took over the operation of the lines in Bolivia. Many of the steam engines and disused wagons were abandoned in yards outside the town and can be visited in what is now known as the Cementerio de Trenes / Train cemetery, one of Uyuni's main tourist attractions. Passenger trains still run from Oruro via Uyuni to Villazon and also from Uyuni to Calama in Chile (mainly freight).