More than 80 migrants on board a Spanish charity rescue ship exploded with joy at the news that Italy is seizing the boat, allowing them to get off on the island of Lampedusa.
The Open Arms rescue ship has been at sea for 19 days, spending much of that time anchored in the Mediterranean within sight of the Italian island.
Italy's hard-line interior minister Matteo Salvini had refused to let the ship dock.
Some of the migrants - desperate and said to be suicidal amid the crowded and deteriorating conditions - began jumping into the sea to try to get to shore.
The Open Arms charity that sponsors the rescue ship said people were sleeping side by side on deck and forced to share just two toilets.
An Italian prosecutor Tuesday ordered the government to take over the ship as part of what the Italian news agency ANSA said were possible kidnapping charges against Salvini because of his refusal to let the ship dock.
"Finally, the nightmare ends, and 83 people on board will receive immediate assistance on land," Open Arms said. The charity added that the Italian seizure of its ship is a price the charity has to pay to get the migrants the help they need.
Spain is reportedly sending a navy ship to Lampedusa to help care for the migrants and escort them and the Open Arms vessel to the Spanish island of Mallorca.
Several European nations, including France, Germany, Luxembourg, Portugal and Romania, have offered to accept the migrants.
Italian Transport Minister Danilo Toninelli said he welcomes Spain's help and that he hopes Spain will take steps in the future to prevent another crisis involving Open Arms.
Under international law, a distressed ship is supposed to head to the first safe port, which was Lampedusa.
But Salvini has said Italy has done enough in accepting African migrants and demanded that other EU nations do more to help. He also called private charity migrant ships "taxis" for human traffickers.
A second ship, the Ocean Viking - operated by French charities Doctors Without Borders and SOS Mediterranean - is also at sea with 356 mainly Sudanese migrants looking for a safe port.
Lampedusa is the closest EU port from Libyan shores, where thousands of migrants looking to escape war and poverty try crossing the Mediterranean in search of safety, often aboard rickety vessels and flimsy rafts.
Those not rescued by charity ships are left to drown. Migrants picked up by the Libyan coast guard are returned to Libya and housed in migrant detention centers near Tripoli.
Some of those centers are caught in the fighting between rival Libyan governments.
Two missiles slammed into one detention center last month, killing 53.