A charity organisation 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.
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.”
Report says the minors are aged between 13 and 17 and come from Eritrea, Ghana, Nigeria and Sudan.
Aid worker Aloys Vimard, also on board said 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 immigration policy.
He refused to let the ship in, saying: “Saving lives is a duty, turning Italy into a huge refugee camp is not.”