After European leaders from Italy and Malta refused to accept a ship with over 600 mostly Africans aboard, it took the new prime minister of Spain to allow the stranded migrants a safe refuge.
Pedro Sanchez, who took office a week ago, said the ship could dock in the Spanish city of Valencia.
The migrants had been picked up from inflatable boats off the coast of Libya over the weekend, in six different rescue operations, according to the NGO SOS Méditerranée.
“It is our duty to help avoid a humanitarian catastrophe and offer a safe port to these people, to comply with our human rights obligations,” Mr Sanchez’s office said.
Those saved include 123 unaccompanied minors, 11 younger children and seven pregnant women, SOS Méditerranée said.
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.
“Most of them are sleeping outside. They are obviously exhausted, they have been exposed to the elements, they have been at sea for 20 to 30 hours prior to their rescue,” she told the BBC.
“They are fragile and we have yet to learn what’s going to happen to them,” she added.
Moments before, Italy’s far-right interior minister, Matteo Salvini 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 wrote on Twitter, with the hashtag #closethedoors.