TRIPOLI, Libya — The guard forced the migrants to kneel and began barking orders in Arabic, a language that few of the once-hopeful souls who had traveled to Libya from sub-Saharan Africa spoke. A gaunt, elderly man in ripped jeans and a tattered T-shirt failed to comply. The guard, wearing a crisp new uniform emblazoned with the insignia of Libya’s anti-illegal immigration police division, raised his wooden club and brought it down hard on the man’s back, driving him face down into the ground with the first blow.

It was early May, three weeks after the staff at the Triq al-Sikka migrant detention center in the Libyan capital of Tripoli had received human rights training from the International Organization for Migration (IOM). The guard struck the elderly man again on the back and clubbed the back of his legs. Then he moved methodically down the line of kneeling migrants, beating each man as if he were responsible for his fellow prisoner’s infraction. Cries of pain echoed through the barren, warehouse-like facility, where more than 100 half-starved migrants were locked away in crowded cells. Some had been there for months, enduring regular beatings and surviving on a few handfuls of macaroni and a single packet of juice each day. Others had recently been rounded up off the streets in raids targeting black African migrants.

Soon after the beatings began, other guards at the facility noticed my presence and quickly ushered me into a waiting area outside the well-appointed office of Col. Mohamed Beshr, the urbane head of Libya’s anti-illegal immigration police. Beshr is a key player in recent joint EU-Libyan efforts to halt migration to Europe, including intercepting migrants at sea and detaining them on land. He has welcomed high-level European diplomats and U.N. representatives to the Triq al-Sikka facility, and his office is filled with certificates from workshops run by IOM, the European Union, and Britain’s development agency.

Yet Beshr seemed frustrated by my questions about the abuses openly taking place at the detention center he oversaw. To hear him tell it, his European partners cared about only one thing, even if they wouldn’t say it: preventing migrants from showing up on Italy’s shores. “Are they looking for a real solution to this humanitarian crisis?” Beshr asked, smirking and raising his eyebrows. “Or do they just want us to be the place where migrants are stopped?”

Eighteen months after the EU unveiled its controversial plan to curb illegal migration through Libya — now the primary point of departure for sub-Saharan Africans crossing the Mediterranean Sea to Europe — migrants have become a commodity to be captured, sold, traded, and leveraged. Regardless of their immigration status, they are hunted down by militias loyal to Libya’s U.N.-backed government, caged in overcrowded prisons, and sold on open markets that human rights advocates have likened to slave auctions. They have been tortured, raped, and killed — abuses that are sometimes broadcast online by the abusers themselves as they attempt to extract ransoms from migrants’ families.

The detention-industrial complex that has taken hold in war-torn Libya is not purely the result of a breakdown in order or the work of militias run amok in a state of anarchy. Visits to five different detention centers and interviews with dozens of Libyan militia leaders, government officials, migrants, and local NGO officials indicate that it is the consequence of hundreds of millions of dollars in pledged and anticipated support from European nations as they try to stem the flow of unwanted migrants toward their shores.

The European Union has so far pledged roughly $160 million for new detention facilities to warehouse migrants before they can be deported back to their home countries and to train and equip the Libyan coast guard so that it can intercept migrant boats at sea. Individual EU member states have earmarked tens of millions of dollars more as they consider a recent request, reportedly in the range of $900 million, by Libya’s U.N.-backed government in Tripoli for a list of equipment needed to combat migrant smuggling.

EU efforts in Libya are part of a broader plan to stem migration from Africa to Europe, which includes a multibillion-dollar EU Emergency Trust Fund for Africa that aims to address the “root causes” of migration and displacement. In the so-called “source” countries that large numbers of migrants are leaving, the EU is rolling out new development projects designed to persuade would-be migrants not to leave home in the first place. But in transit countries like Libya and its neighbors to the south, Niger and Sudan, the EU has focused on forcibly preventing migrants from reaching the Mediterranean by providing money for anti-smuggling operations, border patrols, and detention facilities.

Migrants whose boat was intercepted by the Libyan navy wait to be given shoes before they can be moved to a detention center in Tripoli. Image by Peter Tinti. Libya, 2017.

In Libya, these policies have empowered militias and criminal syndicates that have allied themselves with the U.N.-backed government and lined up for European largesse. Some have rebranded themselves as official coast guard units in the expectation that they will receive training and equipment. Others are running detention centers where migrants are systematically mistreated but where the European Union and member states still offer support — including IOM funding to provide health care, psychosocial counseling, and essential items like hygiene kits to migrants. IOM, which is the main implementing partner for EU-funded projects related to migration in Libya, has also helped renovate detention facilities and trained guards to staff them.

IOM claims that it has no choice but to work with whoever runs the facilities. “We are not the body that determines what is a detention center and what is not,” Ashraf Hassan, IOM’s operations officer for Libya, who is based out of neighboring Tunisia for security reasons, said in an email. “We focus on supporting vulnerable migrants in need of our assistance.”

For their part, EU officials deny any responsibility for rights abuses that occur in centers that have received EU funding or at the hands of coast guard and navy units that the EU has trained and equipped. “Respect of human rights and protection of the migrants is the priority of the European Union,” Catherine Ray, a spokeswoman for the EU, said in an email. “We are working to support and protect migrants in Libya with our international partners, such as UNHCR and IOM.”

Such claims are at odds with the troubling reality on the ground, where evidence abounds that European funds are fueling a brutal system of arbitrary imprisonment that denies migrants even their most basic human rights. But as pressure mounts on European leaders to slow the surge of migrants from Africa, they are doubling down on the fledgling partnership with Libya and holding it up as a model for future efforts to curb migration. Referring to Italy’s partnership with the Libyan coast guard, French President Emmanuel Macron said in August, “What has been done by Italy and Libya is a perfect example of what we are aiming for.

Migrants from Bangladesh and Morocco disembark a warship operated by the Libyan navy after their boat was intercepted at sea. Image by Peter Tinti. Libya, 2017.

Europe once had a reliable partner in combating illegal migration from Libya in Muammar al-Qaddafi, who ruled from 1969 to 2011. The North African country had long been a gateway to Europe for migrants and asylum-seekers, its shores just 200 miles across the Mediterranean from the Italian island of Lampedusa. Ever the extortionist, Qaddafi — who once warned that he was the only thing preventing Europe from becoming “black” — struck a deal with Italy in 2008 to stem the flow of migrants as part of a $5 billion reparations package meant to atone for three decades of brutal colonial occupation that ended in 1943.

Then the Arab Spring swept across North Africa. The chaos that followed Qaddafi’s demise proved an inviting climate for smugglers, and within a few years Libya had become an unsupervised highway for migrants and asylum-seekers headed to Europe. More than 500,000 migrants have reached Italy via what experts call the “Central Mediterranean route” from North Africa since 2014, the vast majority of whom embarked from Libya. Despite a mysterious lull in migrants taking this route since mid-July, reportedly because a new Libyan militia has begun stopping migrant boats west of Tripoli, nearly 100,000 people have crossed via the Central Mediterranean route in the first nine months of this year. Since 2014, almost 13,000 migrants have perished at sea along this route.

Nearly six years after Qaddafi’s death, Libya has two main rival governments — one in Tripoli and the other in the eastern city of Tobruk — and thousands of square miles of territory controlled by a mosaic of tribal factions, militias, armed groups, and the Islamic State. Even in the capital, where the U.N.-backed Government of National Accord is based, masked men in military fatigues, part of an ever-shifting array of alliances, guard checkpoints by day and exchange gunfire by night. Street-by-street gun battles and tit-for-tat kidnappings are the norm, often serving as proxy battles for larger power struggles that reverberate all the way back to tribal enclaves hundreds of miles away.

Abd al-Rahman Milad, more commonly known as “Bija,” discusses his improbable rise to Libyan coast guard commander at a cafe in the coastal city of Zawiya. Image by Peter Tinti. Libya, 2017.

Unable to rely on a strongman like Qaddafi to keep migrants from departing Libyan shores, Europe has gone in search of new partners, including the ethnic and tribal militias that are now the de facto authorities in most of the country. Many of these militias are nominally allied with the U.N.-backed government led by Prime Minister Fayez al-Sarraj, whose control barely extends beyond the parking lot of its headquarters in central Tripoli. Technically, these armed groups fall under the authority of the Interior Ministry, but in practice they answer to no one.

Some of these militias used to profit from the migrant trade, either by offering protection to smugglers or by smuggling migrants themselves. Now as they position themselves as potential partners to Europe in the fight against illegal migration, they have begun intercepting migrant boats at sea, raiding migrant safe houses, carrying out mass roundups in immigrant neighborhoods, and opening detention centers throughout the country. Many are still involved in other illegal activities such as fuel smuggling and trafficking arms, narcotics, and stolen goods, but EU-funded agencies continue to train their foot soldiers and offer them material assistance in the hope of building a professional coast guard that can clamp down on smugglers at sea.

One such character is Abd al-Rahman Milad, more commonly known as “Bija,” a powerful militia leader-turned-coast guard commander in the coastal town of Zawiya who has allegedly continued to profit from multiple smuggling operations even as he sells himself as a viable EU partner by intercepting migrants at sea. Over cups of coffee and Marlboro Reds at a local cafe in Zawiya, he told the story of his meteoric rise from a newly minted coast guard academy graduate in 2011, just before the revolution that overthrew Qaddafi, to the man who controls the seas outside the city’s strategic port and oil refinery. He had the right combination of tribal alliances and seafaring skills, he said. But Bija’s ascent also involved something common to many of Libya’s post-Qaddafi success stories: a willingness to simply seize what he wanted. “I took control of this port in Zawiya because at the time there was no one doing the job,” he said.

Now that his militia has been recognized as a coast guard unit, Bija is an official agent of the U.N.-backed government in Tripoli. But a recent report by the U.N. Panel of Experts on Libya accuses Bija of working with migrant smugglers in the key smuggling hubs of Sabratha and Zuwara — intercepting only the smugglers backed by rival militias. The human cargo his men corral is then delivered to the Nasr detention center in Zawiya, which is run by a militia he is allied with. The report also criticizes his tactics, which allegedly include “the sinking of migrant boats using firearms.”

Bija denies these allegations and claims they were invented by his rivals, including powerful officials in Tripoli, who fed the U.N. false information in an effort to discredit him. He tells the story of an incident in 2014, when he intercepted a Russian vessel smuggling fuel inside Libyan waters. According to Bija, navy officials in Tripoli ordered him to release the ship and its crew. He refused initially but relented after the officials implied they might back Bija’s local rivals in an effort to oust him. “I have had problems with them [the navy] since that day,” he told me. “But I have never stopped my work, and I am doing what I consider is correct and right.”

The fact that Bija is a controversial figure, however, has not stopped European countries from developing a relationship with him. In May, Bija traveled to Rome to participate in an EU-funded workshop hosted by IOM at the four-star Hotel Clodio, where he met with Italian officials as part of an effort to enhance cooperation on migration. More recently, he said, the Italian government provided him with a new boat to intercept migrants at sea, a picture of which he posted on Facebook with him aboard, smiling for the camera. According to Bija, the Italians have told him more boats are on the way.

Ray, the EU spokeswoman, said she was unaware of any evidence linking EU-trained coast guards to ongoing smuggling operations. “We take your allegations seriously,” she said in an email, adding that the “EU is providing the training because everything that happens within Libyan territorial waters is a Libyan responsibility, not a European one, but this does not mean that we turn a blind eye on it.”

Nigerian migrants inside a locked hangar at the Airport Road detention center in Tripoli, where they had been held for more than a month. Image by Peter Tinti. Libya, 2017.

Traveling to Bija’s fiefdom in Zawiya, along the 30-mile stretch of coastal road that connects the city with Tripoli, requires passing through a half-dozen checkpoints, many of which are controlled by militias whose loyalties and ideologies are as opaque as their motives. The road is often closed, and on days that it is open, one hopes not to attract the attention of bored young men with guns, many of whom are prone to kidnapping Libyans as well as foreigners.

The main road in Zawiya, like most urban centers along the Libyan coast, bears the scars of war. Control of this slice of western Libya — where fortunes are made smuggling fuel, weapons, narcotics, and people — can be extraordinarily lucrative, which explains why rival groups have reportedly put a bounty on Bija’s head. One group that has been a steadfast ally of Bija is the Nasr Brigade, which has spent much of the last year fighting alongside Bija’s coast guard to maintain control over Zawiya and its territorial waters. Led by Mohammad Koshlaf, the Nasr Brigade also controls the Nasr detention center, which is filled with the men, women, and children Bija’s men have intercepted at sea.

Set among pockmarked facades and structures hollowed out by heavy artillery in Zawiya’s industrial zone, the detention center is a sprawling concrete-and-sheet-metal monument to inhumanity. The main hanger is reserved for male inmates, who are packed inside windowless cells for all but a few minutes each day. The only view to the outside is through a single square-foot slot that guards slam shut at their whim. As I passed by, detained migrants reached their hands out and pleaded with me to contact their embassies and take down the numbers of loved ones back home.

The center’s padlocked doors were decorated with stickers from IOM, the European Union, the U.N. refugee agency (UNHCR), and the International Medical Corps, a nonprofit that specializes in humanitarian relief. Representatives from all of these organizations have visited the center and, in the case of IOM and the International Medical Corps, provided hygiene kits and basic medical services with funding from European countries. The militiamen who run the center point to these decals not only as evidence of the quality of their work but of their burgeoning partnership with the EU and the broader international community.

Detainees from West Africa peer out of their overcrowded cell in the Nasr detention center in Zawiya, where migrants intercepted by the coast guard are warehoused indefinitely. Image by Peter Tinti. Libya, 2017.

Migrants who find themselves stuck in places like the Nasr detention center often languish there for months. One way out is through “assisted voluntary return and reintegration,” or AVRR, which European policymakers are eager to promote. Funded by the European Union and member states, and overseen by IOM, the program helps migrants return to their home countries on chartered flights. But to be eligible a migrant’s home country must confirm his or her identity, a complicated process made even more difficult by insecurity in Libya. As of the beginning of August, an overwhelmed IOM had repatriated just 4,346 migrants from detention centers in 2017, a fraction of the estimated 400,000 migrants currently stranded in Libya. (The real number could be much higher, since new centers are sprouting up all the time and in parts of the country that are often impossible for aid workers to access.)

On its website, IOM describes AVRR as the “orderly and humane return and reintegration of migrants who are unable or unwilling to remain in host or transit countries and wish to return voluntarily to their countries of origin.” And while many of the detained migrants I spoke with in Libya expressed a desire to go home after months of suffering in decrepit facilities, it’s unclear whether their return could ever be considered voluntary. Treat anyone bad enough and they will beg to make it stop.

Wajdi Almontaser, the director of the Airport Road detention center in Tripoli, was frank about the poor choices facing migrants in centers like his. “They usually want to go home because they had a bad experience in Libya or because the detention is indefinite, so they use the IOM process to get repatriated and then try again to reach Europe,” he told me.

Mistreatment in these detention facilities doesn’t only take the form of beatings and harassment. The militias also buy and sell their detainees or rent them out as day laborers, to the highest bidder, in a process rights groups have likened to the slave trade. Bambo Jaiteh, a 22-year-old from Gambia who was detained in the Il Khalah detention center outside Tripoli, told me that he had previously been detained in a “prison camp,” where they were loaned out to business people and forced to do manual labor such as heavy debris removal, digging at construction sites, and cleaning. “They took you out to work, and we were only sometimes given food,” he said.

Militias also profit by selling arrested African migrants to smugglers, who expect to collect fees from family members before placing them on boats to Italy. But the real prize is access to the hundreds of millions of dollars promised to underwrite the counter-migration machine.

Migrants from West Africa in their crowded living quarters in the Abu Salim detention center in Tripoli. Image by Peter Tinti. Libya, 2017

As soon as European leaders recalibrated their entire foreign policy toward Libya — and much of Africa — around the goal of stemming migration, many of the same militias once directly involved in migrant smuggling and human trafficking began to see migrant detention as a promising growth industry. Over the course of dozens of interviews in Libya, militia leaders, government officials, and representatives from local NGOs all used the word “business” — in English, rather than Arabic — to explain why so many militias are adding the arrest and detention of migrants to their portfolio of services.

Militias are now racing to outdo each other in the eyes of their European benefactors. Many of the men, women, and children caught up in the dragnet of Libya’s migration crackdown had no intention of going to Europe in the first place. Some of them were even in the country legally. At the Abu Salim detention center in Tripoli, several migrants from Mali and Niger who were detained after a raid in a predominantly “black African” neighborhood told me that they had valid papers and had come to Libya for work. They may never have intended to go to Europe, but they are now caught up in the detention-and-deportation machine designed to keep others from getting there.

According to Frederic Wehrey, a senior fellow at the Carnegie Endowment for International Peace who specializes in post-conflict transitions, the process unfolding around migration in Libya in many ways mirrors U.S. and European engagement with various Libyan actors to combat the Islamic State, also known as ISIS. “In the fight against ISIS, whatever militia was in proximity to an ISIS stronghold would come forward and present themselves as the best option for tackling ISIS,” he said. “These groups catch on very quickly that this is the way the game works,” he continued. “And they use this to outmaneuver their rivals and build up power.”

Foreign governments, along with aid and humanitarian organizations, can all claim they are partnering with groups and individuals who are technically registered as part of the government, but these arrangements are a “thin disguise,” according to Wehrey. “Just because someone is under the Ministry of Interior does not mean they are not acting autonomously and running their own show.”

The European Union’s willingness to partner with militias, however thinly disguised as government agents, has created a market for the detention, sale, and abuse of migrants. It also risks accelerating the fragmentation of the state, officials and outside experts warn. “There is one argument that you start local and build up, that maybe this local engagement is how you build things from the bottom up,” Wehrey said. “But my sense is that if you are creating warlords through this type of engagement, that is not a good thing.”

Authorities in Tripoli agree, arguing that a misalignment in priorities between Libya and the European Union risks undermining the larger goal of putting the Libyan state back together. “We have priorities, and they [the EU] have priorities, and each one is looking out for themselves,” said Anwar Sherif, who heads the special operation unit of the Libyan navy, which, like the coast guard, only has a few functioning boats. “They [the EU] say Libya is unstable and then also say Libya refuses to stop illegal migration. This is stupid. The priority should be stability in Libya.”

One afternoon in the port of Tripoli, Sherif and I watched as Libyan authorities, with help from the UNHCR and IOM, processed 400 migrants they had recently intercepted at sea. As the dejected migrants prepared to board buses destined for detention centers, Sherif pointed across the dock to two merchant vessels moored off in the distance, one of them Ukrainian and the other Turkish. The Libyan navy had caught them both the week before, he said, carrying 132 million gallons of stolen fuel between them. It was a rare win for the navy, which had managed to outgun the two ships over the course of a two-hour firefight. Most of the time, Sherif and his colleagues told me, they are unable able to act on the dozens of reports they receive each day about smuggling ships that are thought to be siphoning off the country’s economic lifeline on an industrial scale.

Migrants from Senegal look out into the prison courtyard from their overcrowded jail cell in the Abu Salim detention center. Image by Peter Tinti. Libya, 2017.

Given that oil revenues are considered crucial to stabilizing Libya, one would think that preventing fuel theft would be a mutual priority shared by Libya and the international community. Yet, according to Sherif, the only conversations his European counterparts are willing to have with him when it comes to training, funding, and equipment are about migrant smuggling. “We are open to improving ourselves, upgrading our knowledge, and bringing our skills up to international standards, but our job is to protect our nation’s sovereignty, not just focus on migrants in the sea.”

There is another problem as well: Many of the most prominent fuel smugglers along the Libyan coast are officially registered under the Interior Ministry, according to Sherif, and are the same coast guard units with which the EU is now partnering to combat migrant smuggling. Sherif won’t name anyone specifically — but he mentions a certain coast guard official who operates out of the port of Zawiya and was recently in Rome meeting with European officials.

Yet according to navy officials like Sherif and his colleague, spokesman Abyoub Qassem, European powers are unwilling to look too closely at what unsavory partners like Bija are up to so long as they fight migration. “Europe wants to use Libya as its Berlin Wall to divide Africa from Europe,” said Qassem, adding that he objects to high-minded criticism from Europeans about human rights. “Europe wants to keep its human rights trademark and keep its own reputation clean.”