An angry mob then beat the train driver severely and set fire to the coaches in retaliation, officials said.
The pilgrims were crossing the tracks at the station in Dhamara Ghat, a small town in Bihar state, eastern India, when they were struck by the Rajya Rani Express train, said Dinesh Chandra Yadav. Several other people were injured.
PN Rai, a railway official in Bihar, said 35 people died when the train, running at high speed, hit people on the track.
Arunendra Kumar, a senior railway official, said the train was not supposed to stop at Dhamara Ghat and had been given clearance to pass through the station. However, some pilgrims waited on the tracks thinking they could stop the train.
The train stopped a few hundred yards beyond the spot where it hit the pilgrims. Angry mobs then pulled the train driver out and beat him.
The mob then got all the passengers out of the train and set some coaches on fire. Groups of young men also smashed the windows of two other trains that were in the station.
Around 5000 people later gathered near the station and were chasing away district officials who tried to remove the bodies from the tracks.
Yesterday was the last day of month-long prayer ceremonies at the Katyayani temple near Dhamara Ghat.