A charity looking after 629 rescued migrants on a ship stranded off Malta says two Italian vessels will help take them to the Spanish port of Valencia.
SOS Méditerranée and Spanish officials said the Aquarius would be joined by an Italian coastguard ship and a warship.
The migrants were picked up from inflatable boats off Libya at the weekend. Both Italy and Malta had refused to let the Aquarius dock.
SOS Méditerranée tweeted photos of supplies arriving on board on Tuesday.
Earlier the crew said the ship could not sail to Spain while it was overcrowded, and conditions at sea were deteriorating.
- Reality Check: Claims about migrants arriving in Italy
- Desperate migrants rescued from the sea
- UN sanctions for people traffickers in Libya
It has been supplied with fresh provisions by the Maltese navy and the Italian authorities.
The Italian coastguard says the voyage to Valencia is expected to take four days.
It names the coastguard ship as the Dattilo, and says migrants will be taken aboard it and the warship in the coming hours. There are medics and UN Children’s Fund (Unicef) workers on the Dattilo.
Spain’s Prime Minister Pedro Sánchez, who took office a week ago, said he would give “safe harbour” to the Aquarius, after Italy and Malta had refused.
The nationalist authorities on the French island of Corsica also offered to receive the Aquarius, before the latest plan involving Italian ships was announced.
Among the migrants are seven pregnant women, 11 young children and 123 unaccompanied minors.
Doctors without Borders (MSF), which operates the ship with SOS Méditerranée, says 15 migrants have serious chemical burns and several suffered hypothermia.
The UN refugee agency and the EU had both called for a swift end to the standoff between Italy and Malta.
The Council of Europe welcomed Spain’s move, with the organisation’s Commissioner for Human Rights, Dunja Mijatovic, tweeting: “Saving lives at sea is an obligation that states must always uphold.”
The minors are aged between 13 and 17 and come from Eritrea, Ghana, Nigeria and Sudan, according to a journalist on the ship, Anelise Borges.
Aid worker Aloys Vimard, also on board, told the BBC the migrants were afraid they would be returned to Libya.
Malta’s Prime Minister Joseph Muscat tweeted his gratitude to Spain, saying Italy had broken international rules and caused the standoff.
Spain’s decision was hailed by Italian Interior Minister Matteo Salvini as a “victory” for his government’s hardline immigration policy.
He refused to let the ship in, saying: “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 tweeted, with the hashtag #closethedoors.
His right-wing League party campaigned to stop the migrant influx to Italy and deport undocumented migrants. Most of those who survive perilous voyages from North Africa end up in overcrowded Italian migrant camps.
What is the law on accepting ships?
Rules on disembarking and assisting rescue ships such as Aquarius are governed by international law.
The International Convention for the Safety of Life at Sea dictates that any ship learning of distress at sea must assist regardless of the circumstances.
It says that the country responsible for operations in that area has primary responsibility for taking them from the ship.
It also clearly states that the relevant government “shall arrange for such disembarkation to be effected as soon as reasonably practicable”.
A big question for Spain: What happens to the next ship?
By Kevin Connolly, Europe correspondent, BBC News
The European Union wrote its rules about how migrants should be handled in the 1990s when no-one could have imagined the collapse of Libya would create huge flows of desperate people heading across the Mediterranean from sub-Saharan Africa and the Middle East.
The rules say migrants are the responsibility of the first member state where they land – an overwhelming problem in countries like Greece and Italy where the election of a populist government is at least in part a response to the pressure. So the migrants are starting to shape the politics of Southern Europe.
And when Matteo Salvini proclaims “victory”, he’s telling his voters that the promise of a tougher line on immigration is real.
He’s challenging the EU to find a proper solution too, based on forcing other member states to accept quotas of migrants – something it’s failed to do so far. And he’s incidentally created a big question for Spain. Will its offer to the Aquarius be extended to further ships in the future?
Stranded migrants: Italian ships join Aquarius in voyage to Spain