One person has died and dozens have been injured after a landslide derailed a commuter train travelling to Barcelona.

The regional civil protection agency said two train cars from a convoy of six went off the tracks at 6.15am near Vacarisses, around 45 kilometres northwest of Barcelona.

Spanish railway operator spokesman Antonio Carmona has told local media heavy rain in the area over the past few days could have caused the landslide.

Firefighters and emergency workers evacuated 131 commuters and sent five of the 41 people injured to hospital, according to the agency.

Recent downpours have battered Spain. A woman died on Sunday after a river flooded its banks in the northwestern Galicia region.

And on Monday, huge waves swept away the balconies of a sea-side apartment building on the Canary island of Tenerife.

The heavy rains have also caused travel disruption and damage to farmland across the country.