ROME -- Italy's new "Italians first" government claimed victory Monday when the Spanish prime minister offered safe harbour to a private rescue ship after Italy and Malta refused to allow it permission to disembark its 629 migrant passengers in their ports.

The Aquarius, a rescue vessel operated by aid group SOS Mediterranee, has been stuck in the Mediterranean Sea since Saturday, when Italy refused its crew permission to dock and demanded that Malta do so. Malta refused on Sunday.

Spain's new Socialist prime minister, Pedro Sanchez stepped in Monday, ordering authorities in Valencia to prepare for the ship's arrival.

"It's our duty to avoid a humanitarian catastrophe and offer a secure port for these people," Sanchez said.

Both the ship and its passengers were caught up in a political dispute that might not have happened weeks ago.

One of the coalition partners in the populist government that took over in Italy on June 1, the right-wing League, promised voters other European Union countries would be made to share the burden of caring for asylum-seekers who set out for Europe on unseaworthy smugglers' boats.

"Evidently it pays to raise one's voice, something Italy hasn't done as long as one can remember," Italian Interior Minister Matteo Salvini, the League's leader, said Monday at party headquarters.

For those aboard the Aquarius, Spain's offer of docking rights at the port of Valencia was welcome news, although it did not provide a quick or easy solution. By Monday evening, the ship was more than 1,400 kilometres (over 750 nautical miles) from Valencia and still awaiting formal instructions to head to Spain as weather forecasts predicted worsening conditions.

It was unclear if the days of sailing west it would take to get to Spain were feasible, SOS Mediterranee Maritime Operations Manager Antoine Laurent said. The traumatized, exhausted passengers include 120 minors, many of them travelling alone, and seven pregnant women. Several migrants had water in their lungs, suffered hypothermia or burns from a mix of boat fuel and seawater while in their traffickers' boats.

Malta had food and water ferried Monday to the Aquarius, which was running out of supplies.

"The situation is stable but it cannot run" on forever, Laurent said.

A doctor aboard the ship, David Beversluis, said one passenger had to be revived after he was rescued.

"All the survivors are exhausted and dehydrated because they spent many hours adrift in these boats," he said.

Even as the Aquarius' crew grappled with the logistics, Italy vowed to block other rescue boats, including the Dutch-flagged Sea-Watch 3, another aid group's boat. Like the Aquarius, the Sea-Watch 3 rescued migrants in the waters off Libya, where human smugglers are based and asylum-hopefuls have reported torture, beatings, rape and scarce rations in migrant detention centres.

"Little changes if the boat is called Aquarius or Sea-Watch 3," Salvini, the interior minister, said. "We want to put an end to this traffic in human beings. And, so, as we have raised the problem for the Aquarius, we'll do it for all the other boats."

Even as he drew his line, an Italian coast guard vessel with 936 migrants and two migrants' bodies on board was headed toward Catania, Sicily, where it was expected to dock on Tuesday evening, Italian news agency ANSA said. The passengers were rescued in seven separate operations.

The exulting by Salvini, who is also deputy premier, nearly eclipsed the satisfaction expressed by his fellow deputy, Luigi Di Maio, who leads the governing coalition's senior partner, the euroskeptic 5-Star Movement.

Spain's offer is "important news, since it signals a turning point," Di Maio said.

The vast majority of the people travelling on the Aquarius -- 400 -- were rescued by Italian coast guard and navy vessels as well as cargo ships in the waters off Libya. They were transferred to the Aquarius on Saturday before the standoff developed.

Given that the aid ship had no emergency, Italy decided to appeal to other European countries "so they don't leave Italy alone yet again in managing the migratory flows, which is a phenomenon that is all of Europe's business," Di Maio said in a Facebook post.

Under a European Union agreement, the country where asylum-seekers arrive and are identified must care for them until their asylum requests are decided, a process that can take a couple of years.

The refusals by Italy and Malta, leaving the Aquarius unable to quickly bring the migrants to a safe port, dismayed others.

"The duty of a democratic government is not to look away" in a humanitarian crisis, said Barcelona Mayor Ada Colau, who also offered her port as a potential solution to the standoff.

Italy had argued that Malta, a tiny island nation that also is an EU member, was the safest, closest port to the ship. Malta, which in the last few years has only accepted a few hundred migrants, refused, retorting that it bore no responsibility because Italy had co-ordinated the rescues in Libya's search-and-rescue zone.

Maltese Premier Joseph Muscat accused Italy of violating international norms governing sea rescues and said the government's stance risked "creating a dangerous situation for all those involved." He thanked Spain for stepping in.

Italy's premier, Giuseppe Conte, a political novice who backs the 5-Star Movement, on Monday was touring towns in struck by a 2016 quake. He hailed Spain's decision as a "gesture of solidarity" on behalf of the European Union.

The decision by Sanchez "to exceptionally allow a rescue ship, Aquarius, to dock in his country is courageous and welcome," the head of the United Nations refugee agency, Filippo Grandi, said.

Doctors Without Borders tweeted a video of some of the women aboard the ship praying Monday morning. "Thank you, Lord," the women sang.

The passengers, with many migrants from Sudan among them, were apparently unaware of they had become pawns of sorts in Europe's new political equilibrium.

"Italy has stopped bowing our heads and obeying," Salvini said in a Facebook post. "This time we say no."

------

Aritz Parra in Madrid, Nicole Winfield in Rome, Keffrey Schaffer in Paris and Stephen Calleja in Valletta, Malta contributed.