The last thing they heard was the piercing whistle of an oncoming train.

Moments later, dozens of mostly Latin American immigrants who crossed the tracks instead of using an underground passageway to reach a beach party in this seaside resort were dead or injured, their body parts strewn among the rails.

The express train that barreled through the station in northeastern Spain plowed into a group of young men and women that included Ecuadoreans, Chileans, Colombians and Bolivians — leaving 12 people dead, injuring 14 and turning a night of summer solstice celebration into carnage.

Spain's deadliest train accident since 2003 took place during a nationwide ritual on the longest day of the year called Noche de San Juan, or the night of St. John, when the blazing Spanish sun sets at 9:30 p.m.

The crowd got off a commuter train in the beach resort of Castelldefels, a 20-minute train ride outside of Barcelona, shortly before midnight Wednesday. Many jammed an underpass leading to the beach, but about 30 others climbed down from the platform and tried to scurry across the tracks, witnesses said.

Seconds later, a long-distance train that does not stop at the station crashed into the youths at high speed as its drivers sounded the whistle.

Marcelo Cardona, who was on the commuter train, said everyone aboard had been looking forward to dancing around a bonfire on the Mediterranean shore.

"The euphoria of getting off the train immediately became screams. There were people screaming, 'My daughter! My sister!'" said Cardona, a 34-year-old Bolivian. He said he saw "mutilated people, blood everywhere, blood on the platform."

Most of the victims were Latin American immigrants, said Andres Cuantero, head of a team of psychologists sent to counsel grieving relatives. Ecuador's consul for Barcelona, Freddy Arellano Ruiz, told reporters there were victims from his country, and from Bolivia, Chile and Colombia.

As the investigation got under way Thursday, the chairman of the state railway company RENFE, Teofilo Serrano, said he was "almost certain" the long-distance train was not exceeding the speed limit as it traveled through the station. He said he did not know how fast it was going.

The Spanish news agency Europa Press quoted unnamed RENFE officials as saying the train was doing 139 kilometers per hour (87 mph) and the driver tested negative for alcohol and was in shock. RENFE refused to confirm or deny the report.

The Noche de San Juan celebration takes place across Spain but with particular zeal in the Catalonia region where Barcelona is the regional capital. People light bonfires in town squares and on beaches, dance around them, drink beer, barbecue food and set off fireworks.

Felipe Elmaji, a 29-year-old Moroccan traveling with Cardona, said he heard a "thump, thump of the train hitting people."

Cardona's sister Candy recalled the train's whistle as it tried to warn people to get out of the way. "It was horrible. I can't get that sound out of my head," she said.

Cardona said the underpass was jammed with the overflowing crowd from the train. Mayor Joan Sau blamed recklessness for the deaths.

"If the underpass had been used, we would probably not be talking about this tragedy right now," she said.

But Ruiz said some in the group may have been confused after getting off the commuter train because they did not see signs indicating how to reach the underground passageway. They came across an overpass, but it was blocked off, Ruiz said.

Catalan regional Interior Minister Joan Saura said the identification of the mutilated bodies "will not be easy and it will not be fast."

Except for one woman in her 40s, all of the injured were 19 or younger and two are minors, said Marta Joves, spokeswoman for the Catalonia government's civil protection department. Of the 14 injured, one is in extremely critical condition, two are in critical condition and four have been treated and released, she said.

The Catalan regional president, Jose Montilla, said declared a day of mourning as he visited the accident scene Thursday. Flags flew at half-mast at the town hall in Castelldefels and rail crews hosed down the bloodied train tracks. Spanish King Juan Carlos also canceled the annual celebration held in honor of his Saint's day.

Enrique Sosa, a chef who works near the train station, said he rushed to the scene and helped wash off a 16-year-old boy covered in other people's blood.

"He was shaking," said Sosa, a 37-year-old Uruguayan.

Sosa then lent the boy his cell phone so he could call home.

Spain's worst previous train accident came in 2003, when 19 people died in a collision between passenger and freight trains in the southeastern town of Chinchilla.

Get the latest news and more great videos at NewsdayTV Credit: Newsday

Latest on trooper shot on SSP ... What can be done about SALT tax cap ... LI seniors wait-listed for home care ... Get the latest news and more great videos at NewsdayTV

Get the latest news and more great videos at NewsdayTV Credit: Newsday

Latest on trooper shot on SSP ... What can be done about SALT tax cap ... LI seniors wait-listed for home care ... Get the latest news and more great videos at NewsdayTV

SUBSCRIBE

Unlimited Digital AccessOnly 25¢for 6 months

ACT NOWSALE ENDS SOON | CANCEL ANYTIME