A passenger train derailed Wednesday night on a curvy stretch of track in northwestern Spain, killing at least 40 people caught inside toppled cars and injuring more than 140 in the country’s worst rail accident in decades, officials said.

Bodies were covered in blankets next to the tracks, and rescue workers tried to get trapped people out of the train’s cars even as smoke billowed from some of the wreckage. Some passengers were pulled out of broken windows, and one man stood atop a carriage lying on its side and used a pickax to try to smash through a window. Images showed one car pointing up into the air with one of its ends twisted and disfigured, and another severed in two.

Officials gave differing death tolls in the immediate aftermath of the crash just outside Santiago de Compostela, capital of the Galicia region.

Alberto Núñez Feijóo, president of Galicia, said that at least 40 people died. But the president of Galicia’s main court, Miguel Ángel Cadenas, was quoted at the scene by the Cadena Ser radio station as saying that 56 people died. Rescue workers were still searching through the smoldering wreckage Thursday morning in the pre-dawn darkness.

State-owned train operator Renfe said in a statement that 218 passengers and an unspecified number of staff members were on board the eight-carriage train during the 8.41 p.m. crash on a section of tracks about 2.5 miles from Santiago de Compostela that came online two years ago.

A regional Galicia health official, Rocio Mosquera, told reporters early Thursday that more than 140 passengers from the train had been treated at area hospitals.

Officials in Santiago de Compostela canceled ceremonies planned for Thursday, when Catholic pilgrims converge on the city to celebrate a festival honoring Saint James, a disciple of Christ whose remains are said to rest in a shrine. The city is the main gathering point for the faithful who make it to the end of the El Camino de Santiago pilgrimage route that has drawn Christians since the Middle Ages.

Officials said they thought that the crash was an accident but that an investigation was underway. The train started from Madrid and was scheduled to end its journey at Ferrol, about 60 miles north of Santiago de Compostela.

It was Spain’s deadliest train accident since 1972, when an accident on a track heading to the southwestern city of Seville killed 77 people, the Europa Press news agency reported.

— Associated Press