Spain's new prime minister has ordered authorities to allow a rescue ship carrying 629 migrants to dock in the eastern port of Valenica after the boat was refused access by Italy and Malta.
Pedro Sanchez's office said: "It is our duty to avoid a humanitarian catastrophe and offer a secure port for these people."
Amid the political dispute, the Aquarius, a rescue ship belonging to the SOS Mediterranee charity, has been stuck in the Mediterranean Sea with its passengers, including 123 unaccompanied minors and seven pregnant women.
Medical workers said food on board the ship is going to run out by Monday night.
The government statement said Spain wanted to comply with its international responsibilities on humanitarian crises.
This came after the Aquarius and its passengers were caught up in a crackdown swiftly implemented by the right-wing partner in Italy's new populist government, which has vowed to stop the country from becoming the "refugee camp of Europe".
"Starting today, Italy, too, begins to say NO to the trafficking of human beings, NO to the business of clandestine immigration," Interior Minister Matteo Salvini, leader of the anti-migrant League party, tweeted on Sunday.
Mr Salvini and Transportation Minister Danilo Toninelli, who is part of the 5-Star Movement faction in the new government, said in a joint statement that it was Malta's responsibility to "open its ports for the hundreds of the rescued on the NGO ship Aquarius".
"The island can't continue to turn the other way," the ministers said. "The Mediterranean is the sea of all the countries that face it, and it (Malta) can't imagine that Italy will continue to face this giant phenomenon in solitude."
The Maltese government, however, was not moved. It said in a statement that the Aquarius took on the passengers in waters controlled by Libya and where Italian authorities in Rome coordinate search-and-rescue operations.
The Maltese Rescue Coordination Centre "is neither the competent nor the coordinating authority," the statement said.