The 629 people, including seven pregnant women and 100 unaccompanied children, are to make another four-day journey to Valencia just as the Aquarius ship was about to run out of supplies.
People on board the vessel, which has been stranded in the Mediterranean after both Italy and Malta refused to allow it to dock at the weekend, will be transferred to Italian ships and be given food and water.
Italy’s refusal at the weekend marks the first major anti-migrant move since far-right interior minister Matteo Salvini took office this month promising to crack down on illegal immigration.
“Supplies will be received shortly from an Italian vessel onto #Aquarius. Plan from MRCC (the Maritime Rescue Coordination Centre) Rome is that rescued people will later be transferred on Italian ships before heading together to” the eastern Spanish port of Valencia, rescue charity SOS Mediterranee said on Twitter.
Spanish socialist Prime Minister Pedro Sanchez offered to allow the Aquarius to dock in Valencia, insisting it was an “obligation” to do so.
Authorities on the French island of Corsica also offered to host the migrants after SOS Mediterranee raised fears that the Aquarius would not be able to reach Spain safely due to deteriorating weather conditions.
SOS Mediterranee said an approaching storm would bring with it waves of over 2 metres (6.5 ft) making any trip to Spain highly uncomfortable.
“This plan would mean already exhausted rescued people would endure 4 more days travel at sea,” Doctors Without Borders said on Twitter. “(We) call for people’s safety to come before politics.”
It added: “The better option would be to disembark the rescued people in the nearest port after which they can be transferred to Spain or other safe countries for further care and legal processing.”
The migrants were picked up off the Libyan coast at the weekend and were packed onto the Aquarius which is operated by the charities SOS Mediterranee and Medecins san Frontieres.
Malta and Italy both thanked Spain for stepping up, but maintained their dispute over who was responsible.
“VICTORY,” tweeted Italy’s far-right Interior Minister Matteo Salvini.
A statement from the Italian coastguard, said: “In the next few hours, part of the Aquarius ship migrants will be transferred to Dattilo of the Coast Guard ship and to a Navy vessel, in order to allow the transfer of the three units to the Spanish coast, in the conditions of maximum safety possible for the people present on board.”
A European Union summit later this month is due to consider changes to asylum law to better share the burden of incoming migrants.
More than 1.8 million people have entered Europe since 2014, with more than 600,000 arriving in Italy.