Spain offered on Monday to take in a ship stranded in the Mediterranean with 629 migrants aboard after Italy and Malta refused to let the vessel dock in their ports.
The migrants, including pregnant women and scores of children, were saved by the French charity SOS Mediterranee on Saturday.
They were taken on board its ship Aquarius, which is now between Malta and Sicily.
But Malta and Italy -- whose new populist government has vowed a tough new stance on immigration -- have both refused to take the migrants in, triggering concern in the international community about their plight.
Spain's new Socialist Prime Minister Pedro Sanchez agreed to allow the ship to dock in its eastern port of Valencia.
"The prime minister has given instructions for Spain to honour international commitments on humanitarian crises and announced that the country will receive the ship Aquarius," his office said in a statement.
"It is our obligation to help to avoid a humanitarian catastrophe and to offer a safe port to these people."
The UN had called on Malta and Italy to immediately allow the boat to dock, describing the situation as "an urgent humanitarian imperative".
It suggested that the hundreds on board "are running out of provisions."
The EU and the bloc's biggest member state Germany made similar pleas.
"The priority of both the Italian and Maltese authorities should be ensuring these people receive the care they need," European Commission spokesman Margaritis Schinas told reporters, calling for a "swift resolution".
Italy's refusal to take in the migrants is the first sign of the new government's hardened stance on immigration.
Its far-right Interior Minister Matteo Salvini showed no sign of backing down on Monday.
"Saving lives is a duty, turning Italy into a huge refugee camp is not. Italy is done bending over backwards and obeying, this time THERE IS SOMEONE WHO SAYS NO," he wrote on Twitter followed by the hashtag #closethedoors.
The Maltese government insisted it was "acting in full conformity with its international obligations".
SOS Mediterranee tweeted late on Sunday that the Aquarius had received instructions from the Italian Maritime Rescue Coordination Centre to stand by in its current position 35 nautical miles from Italy and 27 nautical miles from Malta.
'Vulnerable patients at risk'
"We haven't moved since last night, people are starting to wonder why we've stopped," journalist Anelise Borges, who is aboard the Aquarius, said in a tweet.
MSF Sea (Doctors Without Borders) said the medical situation of those on board was "stable for now but unnecessary delay to disembarkation in safe port puts vulnerable patients at risk."
"Particularly seven pregnant woman, 15 with serious chemical burns and several critical drowning hypothermia patients," MSF Sea said.
Italian Prime Minister Giuseppe Conte said Sunday that Rome had sent two patrol ships with doctors on board "ready to intervene and ensure the health of anyone on board the Aquarius who might have the need".
The migrants were rescued in six separate night-time operations in the central Mediterranean on Saturday.
"The people we saved yesterday were in a difficult condition, at least 50 were at risk of drowning. We need to have an idea of what port to go to, something that up to now we haven't had," Aquarius crew member Alessandro Porro told news channel Sky TG24 on Sunday.
The French organisation said those brought on board included 123 unaccompanied minors, 11 small children and the seven pregnant women.
'A land of refuge'
Under EU rules migrants must apply for asylum in the European country where they first arrive.
That has put pressure on Italy and Greece, the entry points for hundreds of thousands of people fleeing war and poverty in the Middle East, Africa and Asia since 2015.
Some in Italy have offered to take in migrants. The mayor of Taranto, Rinaldo Melucci said the southern port city was "ready to embrace every life in danger".
"Our land has always been one of refuge, I don't know how you can send away 629 human lives."
Naples mayor Luigi de Magistris said on Twitter that "if a minister without a heart leaves pregnant women, children, old people, human beings to die, the port of Naples is ready to welcome them".
EU leaders in December had set an end-June deadline for an overhaul of rules to create a permanent mechanism to deal with migrants in the event of a new emergency.
The summer of 2016 saw a surge in mass drownings in the Mediterranean, at the peak of Europe's worst migration crisis since World War II.