Spanish Prime Minister Pedro Sanchez has promised to get to the bottom of why two high-speed trains collided in southern Spain killing at least 40 people, as rescuers continue to search the wreckage.

After visiting the site of the crash, Sanchez also announced three days of national mourning for victims.

More than 120 more people were injured as carriages on a Madrid-bound train derailed and crossed over to the opposite tracks, colliding with an oncoming train in Adamuz on Sunday evening.

The crash is the worst the country has seen in more than a decade.

Rail network operator Adif said the collision happened at 19:45 local time (18:45 GMT) on Sunday, about an hour after one of the trains left Málaga heading north to Madrid, when it derailed on a straight stretch of track near the city of Córdoba.

The force of the crash pushed the carriages of the second train into an embankment, according to Transport Minister Óscar Puente. He added that most of those killed and injured were in the front carriages of the second train, which was travelling south from Madrid to Huelva.

Rescue teams said the twisted wreckage of the trains made it difficult to recover people trapped inside the carriages.

Sanchez visited the site of the crash with senior officials on Monday afternoon.

This is a day of sorrow for all of Spain, for our entire country, he told reporters.

We are going to get to the truth, we are going to find the answer, and when that answer about the origin and cause of this tragedy is known, as it could not be otherwise, with absolute transparency and absolute clarity, we will make it public.

Puente said an investigation could take at least a month, describing the incident as extremely strange.

But Reuters news agency quoted an unnamed source briefed on initial investigations as saying experts had found a faulty joint on the rails, which was causing a gap between rail sections to widen as trains travelled over it. They added that the joint was key to identifying the cause of the accident.

Four hundred passengers and staff were on board the two trains, the rail authorities said. Emergency services treated 122 people, with 41, including children, still in hospital. Of those, 12 are in intensive care.

Puente said the death toll is not yet final. Officials are working to identify the dead.

The type of train involved in the crash was a Freccia 1000, which can reach top speeds of 400 km/h (250 mph), a spokesperson for the Italian rail company Ferrovie dello Stato told Reuters.

Salvador Jimenez, a journalist with RTVE who was on one of the trains, said the impact felt like an earthquake.

I was in the first carriage. There was a moment when it felt like an earthquake and the train had indeed derailed, Jimenez said.

Footage from the scene appears to show some train carriages had tipped over on their sides. Rescue workers can be seen scaling the train to pull people out of the lopsided train doors and windows.

All high-speed services between Madrid and the southern cities of Malaga, Cordoba, Sevilla and Huelva have been suspended until Friday.

In 2013, Spain suffered its worst high-speed train derailment in Galicia, north-west Spain, which left 80 people dead and 140 others injured.

Spain's high-speed rail network is the second largest in the world, behind China, connecting more than 50 cities across the country.