ROME — For several years, they were Europe’s lifesaving workhorses — a fleet of humanitarian boats that patrolled the Mediterranean, rescuing migrants in distress and transporting them to the southern shores of this continent.

But now that fleet is shrinking, along with the chances of migrants making it to their intended destination. When migrants need rescue — and they typically do, as the inflatable dinghies they set out in can’t make it far — they are more likely to encounter a Libyan patrol boat that will take them back in the direction they were trying to escape from.

The humanitarian groups and their passengers have been under especially intense pressure this week, as European countries clashed over the obligation to take in migrants, with Italy closing its ports to a vessel from a nongovernmental organization, France chastising Italy, German leaders splitting over the issue and Spain ultimately opening its doors. But the NGOs say their work has been compromised for some time now, as southern Europe has grown increasingly resistant to migrants and Libya has taken on a more active role in patrolling the sea.

Earlier in this migrant crisis, there were often a half-dozen vessels from NGOs working in the Mediterranean. Last week, there was one.

“We couldn’t do our jobs anymore,” said Chris Catrambone, co-founder of the Malta-based Migrant Offshore Aid Station, which has transferred its boat to Southeast Asia to help the Rohingya ethnic minority fleeing Myanmar. “We were rendered ineffective by politics.”

The NGOs say the environment in the Mediterranean began to change last year when Italy, then led by a center-left government and with the backing of the European Union, determined to revive the Libyan coast guard and hand over a large portion of sea rescues.

The Libyan unit had fallen into disrepair after the death in 2011 of dictator Moammar Gaddafi. But last year, Marco Minniti, Italy’s interior minister at the time, traveled frequently to Tripoli. He built goodwill by brokering a peace deal with warring Libyan tribal leaders. He met with Libyan mayors and pushed them to patrol their frontiers. In an interview, Minniti said Italy also delivered seven refurbished patrol vessels and helped to train Libyan coast guard members.

The results have been dramatic. About 22,000 people this year, according to the International Organization for Migration, have attempted to leave Libyan shores for Italy — a 70 percent reduction from the same period last year. But the number of arrivals in Italy is down even more steeply. That’s because the fortified Libyan coast guard has expanded the zone of the Mediterranean it patrols and is intercepting about 1 in every 3 migrants, compared with 1 in 8 last year. The death rate in the central Mediterranean has remained steady.

“Not all problems have been solved, of course,” said Minniti, who said he felt that Italy was shouldering a disproportionate share of Europe’s migration burden. “Still, my feeling is that Italy had faced a challenge that seemed impossible.”

He said NGOs “have an important role to play” but declined to speak about their relationship with the Libyan coast guard. “Libya is a sovereign country and has its own government,” he said.

Italy’s new far-right interior minister, Matteo Salvini — who was the one to close ports to the Aquarius and the 629 migrants on board this past week — has a less favorable view of the NGOs. He sees them as a “taxi” service for migrants who otherwise would have little chance of reaching Italy.

“The NGOs don’t help,” Salvini said in an interview. “Knowingly or unknowingly, they help traffickers.”

As the remaining NGOs tell it, they are providing a vital humanitarian service and preventing thousands of drownings. But the groups say their work has become more dangerous and ethically confusing. The armed Libyan coast guard has been known to ward them off from rescue scenes by firing warning shots. And so the groups face a choice: interfere with the Libyans, risking safety, or turn into bystanders for rescues that end with migrants being returned to Libya and placed in a notoriously brutal detention system where people face the possibility of rape, extortion and forced labor, according to the United Nations.

“That is like the biggest ethical vacuum you can be in,” said Johannes Bayer, the chairman of Sea-Watch, a German rescue group.

Among the nine most prominent organizations performing rescue work in the Mediterranean, three have stopped or suspended their operations over the past year, citing in part concerns about encounters with Libya’s armed coast guard. Another has cut back on its missions. Two groups have been slowed or interrupted amid legal fights in Italy.

The NGOs that have dropped out include Save the Children and Doctors Without Borders, which still sends some of its staff on missions with another charity, SOS Mediterranee.

Barcelona-based Proactiva Open Arms had one of its vessels seized in Sicily for several months, accused by a prosecutor of enabling illegal migration after it failed to hand over migrants to Libya during a contested rescue. A German NGO, Jugend Rettet, had its boat impounded last August in Sicily, with prosecutors saying the group had cooperated with smugglers — an accusation Jugend Rettet describes as false and politically motivated.

In theory, the handling of rescues should be clear-cut: The Rome-based Maritime Rescue Coordination Center (MRCC) assigns the duties to the boat in the best position. But interviews with more than a half-dozen NGO leaders, plus extensive video of rescues, suggest that results can be chaotic and patchwork. Sometimes, Libyans arrive first but then need the help of the NGOs. Sometimes, the NGOs are called to handle the rescues, only to be chased off by Libyans.

Last November, as a migrant boat was deflating off the coast of Tripoli, both the Libyan coast guard and the Sea-Watch 3, operated by a German NGO, arrived on the scene at roughly the same time. In the helter-skelter radio communication with Rome, both thought they were in charge.

“We are now responsible for this rescue, over,” the Libyans told the Sea-Watch 3, according to a 28-minute synopsis of the event, compiled from radio exchanges and boat surveillance footage by Forensic Architecture, a research team based at the University of London.

“Negative,” Sea-Watch 3 said back. “We have orders from the MRCC.”

As migrants screamed in the water, both the NGO and the coast guard helped people to their boats. The Libyans first tried to ward off the Sea-Watch rescuers, then — as one migrant drowned out of their reach — gestured them to return. A few migrants who had been loaded onto the Libyan boat tried to jump back into the water. The Libyan coast guard vessel drove away as one migrant clung to a ladder on its side.

The distance between Africa and Europe was vanishingly thin, and when the rescue ended, 59 people were in the hands of the Sea-Watch 3; another 47 were in the hands of Libya. Rescued migrants report that at least 20 people died, most before the vessels arrived. Video shows that at least two drowned during the operation. Some of the survivors last month filed an application against Italy with the European Court of Human Rights, citing its work with the Libyan coast guard.

The Italian government has asked NGOs operating in the Mediterranean to agree to a code of conduct that commits them “not to obstruct” the search-and-rescue operations of the Libyans. But groups say they handle this differently.

“If you do exactly what the Libyans want, you’re the wrong person for the job,” said Thomas Nuding, who leads missions for the German group Mission Lifeline.

When Libya takes over a rescue, “it’s the end for us,” said Sophie Beau, co-founder of SOS Mediterranee, which operates the Aquarius, the ship rejected by Italy this past week.

“We will not enter into a battle with the Libyan coast guard, where people are armed,” she said. Instead, the Aquarius will stay on the horizon, watching from several miles away. “We had this situation several times, where we had to look completely helpless.”

Stefano Pitrelli contributed to this report.