Beginning in the 1920s, steam locomotives were gradually retired and replaced by diesel and electric locomotives. The timeframe of this process varied by country.

North and South America

United States 

The first diesel locomotives appeared on the Central Railroad of New Jersey in 1925 and on the New York Central in 1927. Moving forward, diesel locomotives began to appear in mainline service in the United States in the mid-1930s. Compared to steam, diesel power reduced maintenance costs dramatically while increasing locomotive availability. On the Chicago, Rock Island and Pacific Railroad, new units delivered over  a year, compared with about  for a mainline steam locomotive. World War II delayed dieselisation in the US until the late 1940s; in 1949, the Gulf, Mobile and Ohio Railroad became the first large mainline railroad to convert completely to diesel locomotives, and Life Magazine ran an article on 5 December 1949 titled "The GM&O puts all its steam engines to torch, becomes first major US railroad to dieselize 100%". The manufacture of new steam locomotives for stateside use decreased as dieselization continued. The Lima Locomotive Works was perhaps the last commercial builder of steam locomotives, with the final order completed being for ten  “Berkshires” for the New York, Chicago & St. Louis Railroad in 1949. The last steam locomotive manufactured for general service in the United States would follow in 1953: a Norfolk and Western , built in the railroad's Roanoke Shops. 1960 is normally considered the final year of regular Class 1 main line standard gauge steam operation in the United States, with operations on the Grand Trunk Western, Illinois Central, Norfolk and Western, and Duluth Missabe and Iron Range Railroads, as well as Canadian Pacific operations in Maine. The Grand Trunk Western did, however, use some steam power for regular passenger trains until 1961, the last instance of this occurring unannounced on trains 56 and 21 in the Detroit area on 20 September 1961 with  6323, one day before its flue time expired. The last steam-powered standard-gauge regular freight service by a class 1 railroad came little over a year later on the isolated Leadville branch of the Colorado and Southern (Burlington Route) on 11 October 1962 with 2-8-0 641. Narrow-gauge steam was used for freight service by the Denver and Rio Grande Western on the  run from Alamosa, Colorado, to Farmington, New Mexico, via Durango until service ceased on 6 December 1968. The Denver and Rio Grande Western would keep its narrow gauge steam power active, however isolated from its main network, until in 1981 when Florida business man Charles Bradshaw bought the Durango and Silverton line from the D&RGW and renamed it the Durango and Silverton Narrow Gauge Railroad with its first season starting in 1982.

The Union Pacific Railroad is the only Class I railroad in the US to have never completely dieselised, at least nominally. It has always had at least one operational steam locomotive, Union Pacific 844, on its roster.

Some US shortlines continued steam operations into the 1960s and beyond; the Northwestern Steel and Wire mill in Sterling, Illinois continued to operate steam locomotives until December 1980, and the Crab Orchard and Egyptian Railway, which had used steam since its inception in 1973, continued until September 1986. By this time, around 1,800 of the over 160,000 steam locomotives built in the United States between 1830 and 1950 still existed, with a fraction still in operating condition at museums, on tourist railroads, or in use on mainline excursions.

Mexico 
On the contiguous North American standard gauge network across Canada, Mexico and the United States, the use of standard gauge main line steam locomotion using s built in 1946 for handling freight between Mexico City and Irapuato lasted until 1968. The Mexican Pacific line, a standard gauge short line in the state of Sinaloa, was reported in August 1987 to still be using steam, with a roster of one , two s and one .

Other countries 
In Paraguay, wood-burning steam locomotives operated until 1999.

Europe

Britain 

Trials of diesel locomotives and railcars began in Britain in the 1930s but made only limited progress. One problem was that British diesel locomotives were often seriously under-powered compared with the steam locomotives against which they were competing. Moreover, labour and coal were relatively cheap.

After 1945, problems associated with post-war reconstruction and the availability of cheap domestic-produced coal kept steam in widespread use throughout the two following decades. However the ready availability of cheap oil led to new dieselisation programmes from 1955, and these began to take full effect from around 1962. By then it was apparent that steam locomotives had reached their limit in terms of power within the restrictive British loading gauge, with no scope for larger boilers or cylinders even if mechanical firing were to be employed.  Towards the end of the steam era, steam motive power fell into a state of disrepair. The last steam locomotive built for mainline British Railways was 92220 Evening Star, which was completed in March 1960. The last steam-hauled service trains on the British Railways network ran on 11 August 1968, but the use of steam locomotives in British industry continued into the 1980s. In June 1975, there were still 41 locations where steam was in regular use, and many more where engines were maintained in reserve in case of diesel failures. Gradually, the decline of the ironstone quarries, steel, coal mining and shipbuilding industries – and the plentiful supply of redundant British Rail diesel shunters as replacements – led to the end of steam power for commercial uses.

Several hundred rebuilt and preserved steam locomotives are still used on preserved volunteer-run 'heritage' railway lines in the UK. A proportion of the locomotives are regularly used on the national rail network by private operators where they run special excursions and touring trains. A new steam locomotive, the LNER Peppercorn Class A1 60163 Tornado has been built (began service in 2009). The builders of this locomotive, the A1 Steam Locomotive Trust have a second new steam locomotive nearing completion, a LNER Class P2 2-8-2 class locomotive to be named Prince of Wales and plans for a LNER Class V4 2-6-2 are in place following the completion of Prince of Wales.

Germany 
After the Second World War, Germany was divided into the Federal Republic of Germany, with the Deutsche Bundesbahn (founded in 1949) as the new state-owned railway, and the German Democratic Republic (GDR), where railway service continued under the old pre-war name Deutsche Reichsbahn.

For a short period after the war, both the Bundesbahn (DB) and Reichsbahn (DR) still placed orders for new steam locomotives. They needed to renew the rolling stock, mostly with steam locomotives designed for accelerated passenger trains. Many of the existing predecessors of those types of steam locomotives in Germany had been lost in the battles or simply reached the end of their lifetime, such as the famous Prussian P 8. There was no need for new freight train engines, however, because thousands of the Classes 50 and 52 had been built during the Second World War.

Because the concept of the so-called "Einheitslokomotiven", the standard locomotives built in the 1920s and 1930s, and still in wide use, was already outdated in the pre-war era, a whole new design for the new steam locomotives was developed by DB and DR, called "Neubaudampflokomotiven" (new-build steam locomotives). The steam locomotives made by the DB in West Germany, under the guidance of Friedrich Witte, represented the latest evolution in steam locomotive construction including fully welded frames, high-performance boilers and roller bearings on all moving parts. Although these new DB classes (10, 23, 65, 66 and 82) were said to be among the finest and best-performing German steam locomotives ever built, none of them exceeded 25 years in service. The last one, 23 105 (still preserved), went into service in 1959.

The Democratic Republic in East Germany began a similar procurement plan, including engines for a narrow gauge. The DR-Neubaudampflokomotiven were the classes 23.10, 25.10, 50.40, 65.10, 83.10, 99.23-24 and 99.77-79. The purchase of new-build steam locomotives by the DR ended in 1960 with 50 4088, the last standard-gauge steam locomotive built in Germany. No locomotive of the classes 25.10 and 83.10 was in service for more than 17 years. The last engines of the classes 23.10, 65.10 and 50.40 were retired in the late 1970s, with some units older than 25 years. Some of the narrow-gauge locomotives are still in service for tourism purposes. Later, during the early 1960s, the DR developed a way to reconstruct older locomotives to conform with contemporary requirements. The high-speed locomotive 18 201 and the class 01.5 are examples of designs from that programme.

Around 1960, the Bundesbahn in West Germany began to phase out all steam-hauled trains over a period of ten years, but still had about 5,000 of them in running condition. Even though DB were very assertive in continuing the electrification on the main lines – in 1963 they reached  of electrified routes – and dieselisation with new developed stock, they had not completely removed steam locomotives within the ten-year goal. In 1972, the Hamburg and Frankfurt departments of the DB rail networks became the first to no longer operate steam locomotives in their areas. The remaining steam locomotives began to gather in rail yards in Rheine, Tübingen, Hof, Saarbrücken, Gelsenkirchen-Bismarck and others, which soon became popular with rail enthusiasts.

In 1975, DB's last steam express train made its final run on the Emsland-Line from Rheine to Norddeich in the upper north of Germany. Two years later, on 26 October 1977, the heavy freight engine 44 903 (computer-based new number 043 903–4) made her final run at the same railway yard. After this date, no regular steam service took place on the network of the DB until their privatisation in 1994.

In the GDR, the Reichsbahn continued steam operation until 1988 on standard gauge tracks for economic and political reasons, despite strong efforts to phase out steam being made since the 1970s. The last locomotives in service where of the classes 50.35 and 52.80, which hauled goods trains on rural main and branch lines. Unlike the DB, there was never a large concentration of steam locomotives in just a few yards in the East, because throughout the DR network the infrastructure for steam locomotives remained intact until the end of the GDR in 1990. This was also the reason that there was never a strict "final cut" at steam operations, with the DR continuing to use steam locomotives from time to time until they merged with the DB in 1994.

On their narrow-gauge lines, however, steam locomotives continued to be used on a daily year-round basis, mainly for tourist reasons. The largest of these is the Harzer Schmalspurbahn (Harz Narrow Gauge Railways) network in the Harz Mountains, but the lines in Saxony and on the coast of the Baltic Sea are also notable. Even though all former DR narrow-gauge railways have undergone privatisation, steam operations are still commonplace there.

The German express locomotive, number 18 201 of the Deutsche Reichsbahn in East Germany, appeared in 1960–61 at Meiningen Steam Locomotive Works as a conversion of the Henschel-Wegmann train locomotive 61 002, the tender from 44 468 and parts of H 45 024 and Class 41. It is the fastest operational steam locomotive in the world.

Russia 
In the USSR, although the first mainline diesel-electric locomotive was built in USSR in 1924, the last steam locomotive (model П36, serial number 251) was built in 1956; it is now in the Museum of Railway Machinery at the former Warsaw Rail Terminal, Saint Petersburg. In the European part of the USSR, almost all steam locomotives were replaced by diesel and electric locomotives in the 1960s; in Siberia and Central Asia, state records verify that L-class s and LV-class s were not retired until 1985. Until 1994, Russia had at least 1,000 steam locomotives stored in operable condition in case of "national emergencies".

Other countries 
In Finland, the first diesels were introduced in the mid-1950s, superseding steam locomotives by the early 1960s. State railways (VR) operated steam locomotives until 1975.

In the Netherlands, the first electric trains appeared in 1908, making the trip from Rotterdam to The Hague. The first diesels were introduced in 1934. As electric and diesel trains performed so well, the decline of steam started just after World War II, with steam traction for the Dutch railways ending on 7th of January 1958. Steam locomotives continued however to be used for industrial purposes. The last steam locomotive was used at the Julia coal mine in 1975.

In Poland, on non-electrified tracks, steam locomotives were superseded almost entirely by diesels by the 1990s. A few steam locomotives, however, operate in the regularly scheduled service from Wolsztyn. After ceasing on 31 March 2014, regular service resumed out of Wolsztyn on 15 May 2017 with weekday runs to Leszno. This operation is maintained as a means of preserving railway heritage and as a tourist attraction. Apart from that, numerous railway museums and heritage railways (mostly narrow gauge) own steam locomotives in working condition.

In France, steam locomotives have not been used for commercial services since 24 September 1975.

In Spain, the first electric trains were introduced in 1911, and the first diesels in 1935, just one year before the Spanish Civil War. National railway company (Renfe) operated steam locomotives until 9 June 1975.

In Bosnia and Herzegovina, some steam locomotives are still used for industrial purposes, for example at the coal mine in Banovići and ArcelorMittal factory in Zenica.

In Portugal, operations in CP with steam locos was ended over its broad gauge net 25 march 1977 and over its narrow gauge in 1986.

Asia

China 

China continued to build mainline steam locomotives until the late 20th century, even building a few examples for American tourist operations. China was the last main-line user of steam locomotives, with use ending officially on the Jining–Tongliao Railway at the end of 2005. Some steam locomotives are  still in use in industrial operation in China. Some coal and other mineral operations maintained an active roster of China Railways JS (建设, "Jiànshè") or China Railways SY (上游, "Shàngyóu") steam locomotives bought secondhand from China Railway. The last steam locomotive built in China was  SY 1772, finished in 1999.  at least six Chinese steam locomotives exist in the United States – 3 QJs bought by the Rail Development Corporation (Nos. 6988 and 7081 for IAIS and No. 7040 for R.J. Corman), a JS bought by the Boone and Scenic Valley Railroad, and two SYs. No. 142 (formerly No. 1647) is owned by the NYSW for tourist operations, re-painted and modified to represent a 1920s-era US locomotive; No. 58 is operated by the Valley Railroad and has been modified to represent New Haven Railroad number 3025.

Japan 

Owing to the destruction of much of the nation's infrastructure during the Second World War, and the cost of electrification and dieselisation, new steam locomotives were built in Japan until 1960. The number of Japanese steam locomotives reached a peak of 5,958 in 1946.

With the booming post-war Japanese economy, steam locomotives were gradually withdrawn from main line service beginning in the early 1960s, and were replaced with diesel and electric locomotives. They were relegated to branch line and sub-main line services for several more years until the late 1960s, when electrification and dieselisation began to increase. From 1970 onwards, steam locomotion was gradually abolished on the Japanese National Railways (JNR):

 Shikoku (April 1970)
 Kanto area (Tokyo) (October 1970),
 Kinki (Osaka, Kyoto area) (September 1973)
 Chubu (Nagoya, Nagano area) (April 1974),
 Tohoku (November 1974),
 Chugoku (Yamaguchi area) (December 1974)
 Kyushu (January 1975)
 Hokkaido (March 1976)

The last regular steam passenger train, pulled by a C57-class locomotive built in 1940, departed from Muroran railway station to Iwamizawa on 14 December 1975. It was then officially retired from service, dismantled and sent to the Tokyo Transportation Museum, where it was inaugurated as an exhibit on 14 May 1976. It was moved to the Saitama Railway Museum in early 2007. The last Japanese main line steam train, D51-241, a D51-class locomotive built in 1939, left Yubari railway station on 24 December 1975. That same day, all steam main line service ended. D51-241 was retired on 10 March 1976, and destroyed in a depot fire a month later, though some parts were preserved.

On 2 March 1976, the only steam locomotive still operating on the JNR, 9600–39679, a 9600-class locomotive built in 1920, made its final journey from Oiwake railway station, ending 104 years of steam locomotion in Japan.

Today steam passenger trains are operated by JR companies on an infrequent excursion/nostalgia basis, their services always prefixed with the letters SL (for steam liner). Examples are SL Hitoyoshi and SL Ginga.

South Korea 

The first steam locomotive in South Korea (Korea at the time) was the Moga (Mogul) 2-6-0, which first ran on 9 September 1899 on the Gyeong-In Line. Other South Korean steam locomotive classes include the Sata, Pureo, Ame, Sig, Mika (USRA Heavy Mikado), Pasi (USRA Light Pacific), Hyeogi (Narrow gauge), Class 901, Mateo, Sori and Tou. Used until 1967, the Pasi 23 is now in the Railroad Museum.

India 
New steam locomotives were built in India well into the early 1970s; the last broad-gauge steam locomotive to be manufactured, Last Star, a WG-class locomotive (No. 10560) was built in June 1970, followed by the last meter-gauge locomotive in February 1972. Steam locomotion continued to predominate on Indian Railways through the early 1980s; in fiscal year 1980–81, there were 7,469 steam locomotives in regular service, compared to 2,403 diesels and 1,036 electrics. Subsequently, steam locomotion was gradually phased out from regular service, beginning with the Southern Railway Zone in 1985; the number of diesel and electric locomotives in regular service surpassed the number of steam locomotives in service in 1987–88. The first electric trains were introduced in India as part of the Bombay suburban railway system on 3 February 1925. The first metre gauge diesel locomotives were introduced in 1955 and broad gauge in 1957. All regular broad-gauge steam service in India ended in 1995, with the final run made from Jalandhar to Ferozpur on 6 December. The last meter-gauge and narrow-gauge steam locomotives in regular service were retired in 2000. After being withdrawn from service, most steam locomotives were scrapped, though some have been preserved in various railway museums. The only steam locomotives remaining in regular service are on India's heritage lines.

Other countries 
In Thailand, all steam locomotives were withdrawn from service between the late 1960s and early 1970s. Most were scrapped in 1980. However, there are about 20 to 30 locomotives preserved for exhibit in important or end-of-the-line stations throughout the country. During the late 1980s, six locomotives were restored to running condition. Most are JNR-built  steam locomotives with the exception of a single .

Indonesia has also used steam locomotives since 1876. The last batch of E10  rack tank locomotives were purchased in 1967 (Kautzor, 2010) from Nippon Sharyo. The last locomotives – the D 52 class, manufactured by the German firm Krupp in 1954 – operated until 1994, when they were replaced by diesel locomotives. Indonesia also purchased the last batch of mallet locomotives from Nippon Sharyo, to be used on the Aceh Railway. In Sumatra Barat (West Sumatra) and Ambarawa some rack railways (with a maximum gradient of 6% in mountainous areas) are now operated for tourism only. There are two rail museums in Indonesia, Taman Mini and Ambarawa (Ambarawa Railway Museum).

In the Philippines, the Manila Railroad retired its entire steam locomotive fleet from mainline service by August 1956 as part of the agency's efforts towards dieselisation. All but three tank locomotives were scrapped by its successor, the Philippine National Railways. The last of such engines ordered were ten Manila Railroad 300 class locomotives in 1951. However, steam locomotives continue to operate in Negros Island for much of the later 20th and the 21st centuries. One sugar mill operates two 0-6-0 steam locomotives as of 2020.

Pakistan Railways still has a regular steam locomotive service; a line operates in the North-West Frontier Province and in Sindh. It has been preserved as a "nostalgia" service for tourism in exotic locales, and is specifically advertised as being for "steam buffs".

In Sri Lanka, one steam locomotive is maintained for private service to power the Viceroy Special.

Africa

South Africa 
In South Africa, the last new steam locomotives purchased were  Garratts from Hunslet Taylor for the  gauge lines in 1968. Another class 25NC locomotive, No. 3450, nicknamed the "Red Devil" because of its colour scheme, received modifications including a prominent set of double side-by-side exhaust stacks. In southern Natal, two former South African Railway  gauge NGG16 Garratts operating on the privatised Port Shepstone and Alfred County Railway (ACR) received some L.D. Porta modifications in 1990, becoming a new NGG16A class.

By 1994 almost all commercial steam locomotives were put out of service, although many of them are preserved in museums or at railway stations for public viewing. Today only a few privately owned steam locomotives are still operating in South Africa, including the ones being used by the 5-star luxury train Rovos Rail, and the tourist trains Outeniqua Tjoe Choo, Apple Express and (until 2008) Banana Express.

Oceania 
By March 1973 in Australia, steam was no longer used for industrial purposes. Diesel locomotives were more efficient and the demand for manual labour for service and repairs was less than for steam. Cheap oil also had cost advantages over coal. Regular scheduled steam services operated from 1998 until 2004 on the West Coast Railway.

In New Zealand's North Island, steam traction ended in 1968 when AB 832 (now stored at the Glenbrook Vintage Railway, Auckland, but owned by the Museum of Transport & Technology) hauled a Farmers Trading Company "Santa Special" from Frankton Junction to Claudelands. In the South Island, due to the inability of the new DJ class diesel locomotives to provide in-train steam heating, steam operations continued using the J and JA class  tender locomotives on the overnight Christchurch-Invercargill expresses, Trains 189/190, until 1971. By this time sufficient FS steam-heating vans were available, thus allowing the last steam locomotives to be withdrawn. Two AB class  tender locomotives, AB 778 and AB 795, were retained at Lyttelton to steam-heat the coaches for the Boat Trains between Christchurch and Lyttelton, until they were restored for the Kingston Flyer tourist train in 1972.

References 

Steam locomotives