A freight train carrying diesel has derailed and burst into flames, with fuel spilling into a nearby river.
About 300 people were evacuated from their homes in Llangennech, near Llanelli in Carmarthenshire, during the "major incident" on Wednesday night.
Natural Resources Wales said it was not safe to try and contain a diesel spill which had gone into the River Loughor.
A driver and engineer, onboard the train, were not injured and are being supported, owners DB Cargo UK said.
Dyfed-Powys Police said the driver had noticed something was wrong with the train, which was travelling from Milford Haven. It then derailed and the fire started.
The blaze, which was still burning Thursday evening, was reported at about 23:20 BST on Wednesday and police said it had been declared a "major incident" due to the "initial risk of harm" to people nearby.
People living within 800m of the fire described seeing "plumes of smoke" and seeing flames from the tracks, when they were evacuated from their homes. They have since been allowed back.
The Rail Accident Investigation Branch (RAIB) said it was carrying out a preliminary examination and gathering evidence.
British Transport Police and Natural Resources Wales said their priorities, once they are able to access the site, were the fire itself and making the scene safe, as well as the environmental issues resulting from the spill.
Bill Kelly, from Network Rail, said damage to the infrastructure was significant and would be further assessed by teams "when it is safe for us to do so".
"In terms of services this will obviously impact the central Wales line... I don't have timescales just yet on when we're likely to get them running again," he added.
"We will be able to continue running freight services using diversionary routes."
Ioan Williams, from Natural Resources Wales, said "a significant volume of diesel has been spilled... we can confirm there is diesel in the River Loughor itself."
Puma Energy confirmed the third party-operated train was carrying its fuel from Milford Haven, in Pembrokeshire, to Theale, near Reading, when three tanks caught fire.
"Our immediate priority is to work with the emergency services, Network Rail, environmental agencies and the train operator to ensure public safety is maintained and any possible environmental impacts are mitigated," a spokesman said.
Puma Energy has not yet confirmed how much fuel the train was carrying, or how much caught fire.
The site of the derailment is close to the Loughor Estuary, which is part of the Carmarthen Bay and Estuaries Special Area of Conservation.
But Aneurin Cox, duty incident manager for Natural Resources Wales, said it was "not currently safe" for workers to get close enough to try and contain the spill while the fire was burning.
"Once it's safe to do so, we will work with our partners to fully assess the environmental impact and advise Network Rail when the clean-up of the site can begin," he said.
"We will also be keeping local angling and cockling groups informed of the latest situation."
The cockle beds in the Burry Inlet - worked by 35 licensed pickers - have been closed following the diesel spill.
Robert Griffiths, secretary of the Burry Inlet Handgatherers Association, said he had been contacted by fisheries officers following a meeting of a number of agencies which monitor the beds.
Mr Griffiths said the extent of any diesel pollution was still being assessed and it was hoped the closure would last only a few days.
'Black, black clouds of smoke in the air'
Louise Perkins, who lives close to the railway line, said she grabbed some stuff and rushed from her home with her children, aged seven, 12 and 19, in the middle of the night.
The 38-year-old was up late watching TV when she heard an enormous bang: "There was this massive fire and black smoke.
"As we left it was just fire - you could see like balls of it puffing up, and the smell... the smell of diesel.
"It was just everywhere, and there were just black, black clouds of smoke in the air."
Ms Perkins said she was "quite worried" when police explained "it could explode".
"At that point my children were up and and they got really distressed," she said.
Her 19-year-old son went to his friend's house while her two younger children went to their grandmother's.
"They were worried - 'oh, what if our house catches fire, what about all the stuff?'" she explained.
"I told them not to panic. But my youngest was really upset, she was just heartbroken, she was crying."
One Twitter user said they could smell burning fuel from "well over a mile away".
'Children and dogs carried'
Councillor Gwyneth Thomas, a former A&E nurse, was at the scene to offer help if needed and said how "hugely impressed" she was by "how calm" the emergency service personnel were.
"Some carried young children and others took their dogs with them," she recalled.
"It's very fortunate that the accident didn't happen closer to Llangennech [railway] station where there are more homes, and evacuation of residents would have been more difficult."
Sandra Thomas has lived on Pontarddulais Road since 1972 and said nothing like this had ever happened before and the fire went up "like a bomb".
"I was terrified - I'm shaking all over," she said, adding police knocked on her door while she was watching TV in bed.
She was sent to the community centre, but was allowed to return home on Thursday morning.
But Ms Thomas became concerned when she looked out of her window at 08:00 to see a large black plume of smoke.
"I don't feel 100% safe in case it sparks off again and the rest of the tankers go up," she added.
Speaking at a press conference just before midday, Supt Andy Morgan, of BTP, said: "While this is an ongoing incident that may go on for some time, we are hugely thankful that no-one has been injured or anything more serious than that has happened here."
When the blaze broke out, 14 pumps, a foam tender and specialist hazardous material officers were sent to the scene, Mid and West Wales Fire and Rescue Service group manager Richard Felton said.
The three tankers that caught fire were being monitored and cooled, he added.
Network Rail has not yet been given permission to clear the site, according to Wales and Borders route director, but his teams are "ready and on standby".
"Our main priority will be to ensure there is a minimal environmental impact," Mr Kelly added.
Supt Ross Evans, of Dyfed-Powys Police, said: "The evacuation no doubt caused a significant amount of disruption for those evacuated in the middle of the night and I would like to personally thank residents for their response, as well as our frontline officers who swiftly moved hundreds of residents out of their homes," he added.
Those evacuated had been asked to meet at Bryn School and Llangennech Community Centre, police added.
Even from a distance, the strong smell of diesel hangs in the air and this morning the fire seemed to kick off again and thick black smoke began rising from the crash site.
I can see the hoses in action where the train is on the tracks, but the view is blocked somewhat by the trees.
The fire has since been damped down again and the smoke has turned white again.
Gary Jones, a councillor for Llangennech, said the fire "seemed to die down and then there seemed to be fresh explosions".
"The height of it was incredible," he told BBC Radio Wales.
The A4138 was closed for more than 13 hours between Troserch Road to junction 48 of the M4 at Hendy before reopening at Thursday lunchtime.
The B4297 between Station Road and the A4138 remains closed.
The fire has also resulted in delays on passenger trains between Llanelli and Llandrindod Wells in Powys, Transport for Wales said.
All lines between the two stations have been closed and TfW said it expected disruption on all routes throughout Thursday.
Buses will be put on for services affected by the fire.
Why is the Loughor estuary important?
- The River Loughor's estuary, along with the Burry Inlet to the west, is designated as a site of special scientific interest
- Its habitat of tidal mudflats, saltmarsh - the largest continuous area in Wales - and rockpools offer important wildlife habitat
- Species of wading birds and wildfowl include oystercatcher, curlew, lapwing, little egret, widgeon, dunlin, plover and teal
- The estuary is known for its fishing grounds, for the likes of flounder, bass and mullet
- Further west, the Burry Inlet's cockle beds are well known, with the industry the third largest in Britain
- In that same area is the WWT Llanelli wetland centre, a popular place for spotting wading birds and wildfowl and the 450 acres of grounds.