The EU has agreed to deploy warships to stop the flow of weapons into Libya, as the bloc wound down a military mission that had once rescued migrants and refugees from drowning in the Mediterranean.

Josep Borrell, the EU’s chief diplomat, announced that 27 foreign ministers had agreed to launch a new operation with naval ships, planes and satellites in order to enforce the UN arms embargo on Libya.

To counter objections that the operation could morph into a rescue mission, Borrell promised the ships would be withdrawn if they became “a pull factor” that encouraged people to attempt the risky crossing from Libya to Europe. This commitment helped lift opposition to the mission from Italy and Austria, whose governments had blocked an earlier compromise.

Borrell hailed the agreement after “the longest discussion that I can remember”, and said he had not been sure at 9am on Monday that an understanding would be reached.

Weapons and foreign mercenaries have been pouring into the war-torn north African country, exposing Europe’s weakness in its own neighbourhood. Over the weekend, the UN deputy special envoy for Libya, Stephanie Williams, described the arms embargo as a joke.

Libya’s latest cycle of violence has pitted Gen Khalifa Haftar, the leader of the Libyan National Army, against the UN-backed government of the prime minister, Fayez al-Sarraj.

Haftar is being funded and armed by the United Arab Emirates, while Russia has provided mercenaries. Sarraj is being supported by Turkey, which has sent as many as 2,000 fighters from Syria. Europe’s diplomatic clout has been hampered, as EU nations have found themselves on opposing sides, with France supporting Haftar and Italy backing Sarraj.

Ships under the new mission – to be known as Operation EU Active Surveillance – will patrol about 60 miles (100km) off the coast of Libya, an area of the Mediterranean that is the main route for weapons into the country.

An internal EU memo, released by the London-based civil liberties group Statewatch, underscores that the EU does not expect to be involved in rescuing people. “Naval assets can be deployed in the areas most relevant to the implementation of the arms embargo, in the eastern part of the area of operation or at least 100km off the Libyan coast, where chances to conduct rescue operations are lower,” it says.

As EU ministers agreed to create the naval operation, they ended Operation Sophia, which was set up in 2015 to combat people-smuggling and prevent loss of life at sea.

Operation’s Sophia’s sea patrols were suspended last March, after Italy’s then government, a populist coalition between a far-right party and anti-establishment party, threatened to veto the entire operation. The mission, which was reduced to satellite monitoring and air patrols, had been named after a child born to a Somali mother rescued at sea along with 453 other people on a German naval ship that was part of an EU operation. The EU’s then foreign policy chief, Federica Mogherini, said the name was “to honour the lives of the people we are saving”.

While Operation Sophia’s remit was later extended to include helping uphold the UN arms embargo on Libya, several EU countries wanted to abandon the name for the newly rebooted weapons-control mission.

“There is a basic consensus that we now want a military operation and not a humanitarian mission,” said Austria’s foreign minister, Alexander Schallenberg.

Borrell, the EU’s outspoken foreign policy chief, had said it was absurd for Austria, a landlocked country without a navy, to block the revival of Operation Sophia. He had also vigorously rejected arguments that the new naval operation would create a pull effect.

Speaking after the foreign ministers’ meeting, Borrell struck a more diplomatic tone, referring to “the legitimate concerns of some member states regarding potential impact on migration flows, so-called “pull effects”. He promised these would be monitored, adding: “In case of the observation of pull factors on migration, maritime assets will be withdrawn from the relevant areas.”