Firefighters tackled an "intensive" blaze today after a freight train carrying fuel derailed and caught fire.
Flames shot 50ft into the air and a huge plume of thick black smoke drifted above the crash scene, near Stewarton in Ayrshire.
A railway bridge partially collapsed and an exclusion zone was set up around the area.
Locals told of seeing a fireball after the accident, which happened shortly after 6am today.
Six of the 10 wagons were derailed and one was alight. Four were still attached to the locomotive, British Transport Police (BTP) said.
The 45-year-old male driver was not hurt and no other injuries were reported.
The BP rail wagons were carrying heating oil and diesel from the Grangemouth refinery to a Scottish Fuels terminal in Kilmarnock when the rear section derailed.
DB Schenker was the train operator.
The accident happened near a bridge which collapsed at Peacock Bank Farm.
The train hit a pylon after it came off the rails. Up to 100 local homes lost power as a result.
John Dicks, who lives a mile from the crash site, told of the immediate aftermath of the crash, with a "raging" fire sending flames shooting 50ft in the air.
"There's just a big fireball with thick black smoke," he told BBC Radio Scotland.
"You can't make out the carriages or anything on the track."
Power supplies to his estate went down at around the time of the crash, said Mr Dicks.
Chief Superintendent Martin Ripley, of BTP, told BBC Radio Scotland: "A freight train which was coming into the depot has caught fire.
"I believe it's a fairly big and intensive fire."
Strathclyde Fire and Rescue Service said there were six fire pumps and a heavy rescue vehicle at the scene.
The Rail Accident Investigation Branch was also there, along with local police and fire crews.
A BTP spokesman said: "We can confirm that at approximately 6.25am this morning, Tuesday 27 January, we received reports of a freight train on fire near a bridge at Peacock Bank Farm (KA3 3EA), outside Stewarton rail station, Ayrshire.
"No injuries have been reported and the driver has been accounted for and is uninjured. Some freight train wagons have been derailed and a bridge has collapsed."
Strathclyde Police said the B778 at Kirkford and the Old Kilmarnock to Stewarton roads were closed.
Scottish Power said up to 100 homes in the Kilmaurs area of Ayrshire lost electricity as a result of the crash.
A spokesman confirmed that some power lines were damaged, and said they have turned off two circuits as a precaution.
The railway line is single track at the point where the accident happened.
Network Rail said disruption on the rail network was likely to go on for much of the day.
Local train services between Barrhead in East Renfrewshire and Kilmarnock were stopped and alternative arrangements put in place for travellers.
Buses were replacing trains between Barrhead and Kilmarnock.
The Glasgow to Carlisle service was running via Barassie.
Strathclyde Fire and Rescue said it had more than 50 firefighters at the scene of the incident.
They went into action at around 10.15am after Scottish Power isolated power to the cable serving the railway line and an overhead cable serving local communities, to make it safe for the fire crews to work.
They used foam to extinguish the blaze, and were said to be close to bringing it under control by 12.30pm.
Assistant Chief Officer Dave Goodhew said: "Our firefighters have been outstanding in tackling this major incident.
"The task of the first crews was to ensure that no members of the public were at risk.
"Once that was established their next priority was their own safety while they dealt with a situation that was potentially explosive.
"Once the fire was extinguished, the next task will be to investigate the environmental impact of the kerosene getting into water sources."
The fire service said its large incident command vehicle and a forward control unit were also at the scene.
Glasgow Scientific Services was assisting with the environmental monitoring.
The fire service said the blaze was extinguished early in the afternoon.
Mr Goodhew said it was fortunate that the accident involved a freight train rather than a passenger train.
He said: "I think the time of day was very, very lucky, and the fact that there were no cars going under the bridge when this incident occurred.
"Luckily nobody was underneath it, no pedestrians. The train, from what we understand, has managed to get over the bridge.
"We were very, very lucky that it was not carriages full of commuters.
"It's very fortuitous it was a cargo train as opposed to a passenger train."
Firefighters will remain at the scene for some time to maintain a foam blanket over ground affected by the fuel leak, and also as a precaution while the freight carriages are lifted back on to the rail track.