British Transport police said crews were called to the blaze at Llangennech, near Llanelli, around 11.20pm on Wednesday.
Three carriages of the train were alight and an evacuation zone was put in place, according to Dyfed-Powys police.
Gary Jones, a county councillor in Carmarthenshire, wrote that “a major incident on the railway line has been declared.”
The transport police said: “Emergency services are currently dealing with an incident on the railway near Llangennech Wales. A large diesel freight train has caught fire.
“A cordon is in place, with roads closed and surrounding homes being evacuated. Please avoid the area.”
Dyfed-Powys police said officers were contacting people living in the evacuation area and asking them to leave their homes and convene at Bryn school.
Superintendent Ross Evans said: “This is a fast-moving situation, which has been declared a major incident.
“There are a significant number of emergency services personnel at the scene and an evacuation zone has been put in place.
“Officers are in contact with people within that area asking them to leave their homes, and we urge people to comply with officers’ requests to ensure a swift and efficient evacuation.”
More about: #Wales