A large ship overturned Wednesday off Libya's coast with more than 500 migrants aboard, right as the Italian navy was approaching for rescue. Crews recovered seven bodies but saved more than 500 people who were thrown into the sea.

The Italian navy said its Bettica patrol ship was responding to a migrant ship in distress when it flipped. A photo of the capsized boat taken by the navy showed migrants scrambling up the side of the overturned ship, perching precariously on the exposed side as they awaited rescue, with hundreds more floating in the sea.

Crews tossed life jackets to those in the water and brought 500 to safety, the navy said in a statement.

The rescue comes one day after the European Union boosted the role of its naval operation in the Mediterranean as increasing numbers of desperate migrants leave the country in unseaworthy boats bound for Italy.

At talks in Brussels, EU foreign ministers agreed to extend the operation, known as Operation Sophia, by a year. They also tasked it with building up the size and skills of Libya's coastguard and navy. In addition, the operation would police a U.N. arms embargo off the coast of Libya once a new U.N. Security Council Resolution granting it permission is endorsed.

"We have agreed today to proceed with operational planning so that we can proceed with decisions as fast as possible," EU foreign policy chief Federica Mogherini told reporters.

She said the training effort, which would probably begin on EU naval ships in international waters, "will be very important to control Libya's territorial waters, together with our Libyan partners, as well as to control the migrant influx."

The EU has long wanted to move Operation Sophia into Libyan waters, and longer-term on to land, to combat migrant smugglers. But its efforts have been hampered by the failure of the Libyans to quickly agree on a widely recognized national unity government that would approve any such move.

Meanwhile, Italian prosecutors said last week they will be seeking an 18-year prison sentence for a Tunisian man who allegedly captained a smugglers' boat that capsized and sank, sending some 800 migrants to their death in the Mediterranean.

The prosecutors on Tuesday also asked the court in Catania to convict the co-defendant, a Syrian who allegedly was the captain's assistant, and sentence him to six years for the April 18, 2015, sinking off Libya.

Twenty-eight people survived, including the defendants, who insist they are migrants, not smugglers. Hundreds of migrants, trapped in the hold, sank with the boat. Italian navy divers have recovered 169 bodies near the wreckage. The navy hopes to raise the wreckage and bring it ashore.

Italian investigators lament that human trafficking masterminds, often based in Libya, elude prosecution.

The Associated Press contributed to this report.