A train travelling through a station near Barcelona has hit a group of young people crossing the tracks, killing at least 12 and injuring 17, a Spanish official said.

A long-distance train passing through the station in Castelldefels hit a group of people crossing the tracks who had just gotten off a commuter train.

The group crossed over the tracks above ground rather than using a designated tunnel underneath, said Jose Ramon Mora, head of the Civil Protection Department for Catalonia regional government.

Spanish radio station Cadena Ser and other Spanish media reported that most of the fatalities and injuries were young people who had just arrived in the town to celebrate at a beach party marking the start of summer.

The train was not supposed to stop at the station and was therefore moving through the area at a high speed, media reports said.