Many people are under the impression that, as a result of the deadly 1902 train crash in the Park Avenue tunnel, steam locomotives were outlawed in New York City. The fact is that the law passed in 1903 prohibited steam locomotives only from 42nd Street north through the Park Avenue tunnel and on the viaduct north of the tunnel between 97th Street and the Harlem River.
Steam locomotives continued to run along the west side of Manhattan into the 1930s. It was the Kaufman Electrification Act of 1923 that mandated that all city railroads be electrified by 1926. The main line was electrified according to mandate, but the railroad found it impractical to electrify the freight network, much of which consisted of track on roadways and included grade crossings along the upper west side. Law suits and injunctions just postponed the inevitable. In 1929 the NYC was given 2 years to electrify and end the steam service which had continued from Spuyten Duyvil to the 72nd Street steam servicing facility and the northern end of the freight yards. The High Line removed the tracks from the streets and an upper west side improvement project took care of the grade crossing issue.
Apparently, the law concerned itself primarily with Manhattan Island and was somewhat lenient in the other boroughs. Through the 1940's the Putnam Division of the New York Central delivered freight and passengers into the Bronx by steam, using small ten wheelers and 0-8-0 switchers. They were prohibited from entering Manhattan. By 1952 the Put was dieselized. Also, in Brooklyn on the docks the BEDT (Brooklyn Eastern District Terminal) used steam dockside tank switchers up until 1963.