A Rodalies commuter train hit the buffers at the end of platform 11 at Barcelona-Término station, Spanish track operator Adif confirmed on Friday morning.
20 passengers were lightly injured, 18 suffered minor injuries and one person was seriously injured, Catalan emergency services said. The injured have all been taken to hospital.
There were no fatalities.
Some of the wheels of the leading carriages derailed, Adif said.
Images posted by passengers and onlookers on Twitter showed how the buffers had smashed into the front of the train at the station, which is also known as Barcelona-Estación de Francia.
The train had been travelling from the town of Sant Vicenç Calders, some 60km south-west of Barcelona.
18 ambulances and 11 fire engines responded to the accident.
Spanish rail operator Renfe has opened a hotline for family and friends who are worried about their loved ones: (0034) 900 101 020.
Renfe and Rodalies Catalunya said the accident had not affected other trains or services.
Track operator Adif announced an investigation had been opened into the causes of the crash.