Spain has accepted a rescue ship carrying 629 migrants which had been turned away by the new Italian government, avoiding a humanitarian crisis and diffusing a political stand-off between two EU countries.

In a statement the country’s new prime minister, Pedro Sanchez, said he had given permission for the MS Aquarius to dock in Valencia, adding his country would welcome all those on board.

Sanchez went on say that “It is our duty to help avoid a humanitarian catastrophe and offer a safe harbour to these people in accordance with international law.”

The decision by the new socialist Spanish government provides a stark contrast to that of its Italian counterpart, which on Sunday took the drastic step of refusing entry to the ship.

Italy’s new interior minister and leader of the far-right League, Matteo Salvini, said on Sunday all Italian ports were closed to Aquarius, and insisted the boat should instead dock in Malta.

“Malta takes in nobody. France pushes people back at the border, Spain defends its frontier with weapons. From today, Italy will also start to say no to human trafficking, no to the business of illegal immigration,” he wrote on Facebook.

Sky News says “the refusal - a realisation of tough anti-immigration promises made by Italy's new government - left those on board in mortal danger and prompted a diplomatic spat over the future of migrants travelling across the Mediterranean”.