The governments of El Salvador, Honduras, Guatemala and Mexico are providing humanitarian assistance to several thousand U.S.-bound migrants left stranded on Mexican soil after a railway bridge collapsed, the Salvadoran Foreign Ministry said.

"El Salvador's consulate in Acayucan, Veracruz, in coordination with those (consulates) of Guatemala and Honduras, along with Mexican authorities" have supplied the migrants with food and medical care, the ministry said in a statement.

The respective consulates are also helping the migrants find shelter, contact their families back home and - on a voluntary basis - facilitating their repatriation, the statement said, urging Salvadorans not to undertake the dangerous journey through Mexico.

Roughly 3,500 mainly Central American migrants have been stuck for nearly a month in Coatzacoalcos, a city in the Mexican Gulf coast state of Veracruz, according to the Mesoamerican Migrants Movement.

A freight train, known as "The Beast," used by many Central Americans to reach central Mexico on the long trek to the United States, derailed on June 17 between Medias Aguas and Tierra Blanca, Veracruz.

"The migrants, among whom there are some pregnant women, children and sick people, face the risk of contracting skin, eye, gastrointestinal and respiratory diseases since they are living, eating and sleeping a few steps from where many people are defecating and urinating," the MMM said.

An estimated 300,000 Central Americans undertake the hazardous journey across Mexico each year on their way to the United States.

The trek is a dangerous one, with criminals and corrupt Mexican officials preying on the migrants.

Gangs kidnap, exploit and murder migrants, who are often targeted in extortion schemes, Mexican officials say.

Central American migrants follow a long route that first takes them into Chiapas state, which is on the border with Guatemala, walking part of the way or riding aboard freight trains, buses and cargo trucks. EFE