The train cars were carrying hot asphalt and molten sulfur, Stillwater County Disaster and Emergency Services said.
Officials shut down drinking water intakes downstream while they evaluated the danger after the 6am accident on Saturday.
An Associated Press reporter witnessed a yellow substance coming out of some of the tank cars.
David Stamey, the county’s chief of emergency services, said there was no immediate danger for the crews working at the site, and the hazardous material was being diluted by the swollen river.
There were three asphalt cars and four sulfur cars in the river.
The train crew was safe and no injuries were reported, Montana Rail Link spokesman Andy Garland said.
The asphalt and sulfur both solidify quickly when exposed to cooler temperatures, he said.
Railroad crews were at the scene in Stillwater County, near the town of Columbus, about about 65 kilometres west of Billings.
Read Related Also: Delta flight diverted after unruly passenger breaks free from restraints
The area is in a sparsely populated section of the Yellowstone River Valley, surrounded by ranch and farmland.
The river there flows away from Yellowstone National Park, which is about 180km southwest.
“We are committed to addressing any potential impacts to the area as a result of this incident and working to understand the reasons behind the accident,” Garland said.
In neighbouring Yellowstone County, officials said they instituted emergency measures at water treatment plants due to the “potential hazmat spill” and asked residents to conserve water.
The cause of the collapse is under investigation. The river was swollen with recent heavy rains, but it’s unclear whether that was a factor.
The Yellowstone saw record flooding in 2022 that caused extensive damage to Yellowstone National Park and adjacent towns in Montana.
The US Environmental Protection Agency notes that sulfur is a common element used as a fertiliser as well as an insecticide, fungicide and rodenticide.