Having traveled across deserts or war zones, migrants are often turned back in the Mediterranean by the Libyan Coast Guard as they try to cross to Europe in overcrowded ships. The poorly trained Coast Guard, often likened to a boat-riding militia, says it pushed back 18,000 people last year. The United Nations says the figure is likely three times higher.

Back on dry land, the European Union says it has lavished funds on projects to help migrants and send them back home, spending $381 million since 2014. But many end up in the detention centers, run by militias and overseen by Libya’s weak United Nations-backed government, where conditions can be squalid, dangerous and inhumane. At some centers, migrants say they have been tortured or treated as slaves.

Others are held for ransom or sold back to smugglers. Many live perilously close to the fighting. Since the battle for Tripoli erupted in April, about 3,800 of the 5,000 detainees have become trapped near the front line, according to the United Nations.

In interviews, officials at Tajoura said they have not been able to provide a regular supply of food to about 600 detainees since the Libyan government failed to renew a catering contract on April 1. Migrants have relied on handouts from the medical charity Doctors Without Borders and local businessmen, they said, and many frequently get just one meal a day.

In May, the United Nations’ refugee agency warned that the detainees faced “unacceptable risks” after an airstrike hit a nearby target, wounding two refugees. But calls for an immediate evacuation of the center were ignored.

“Today we see the tragic consequences we feared when we made that statement,” Charlie Yaxley, a spokesman for the United Nations agency, said in Geneva on Wednesday.