In total, 85 people were injured, two of them seriously, the local emergency services say.
The collision happened when a freight train derailed and collided with a passenger train at Sant Boi de Llobregat station, about 14 km from Barcelona. The accident happened around 6 p.m.
About 100 passengers still on the train were evacuated.