MOGADISHU, Somalia—Last week, the U.N. Security Council unanimously agreed to extend the African Union Mission in Somalia (AMISOM) mandate in the country until May 2019. The security situation has been getting worse by the day. On Sunday, two car bombs killed at least six people; one detonated in the capital, Mogadishu, and the other in a nearby town. A few days before, a popular young entrepreneur was murdered, sparking protests demanding accountability and better security.AMISOM first deployed to Somalia in 2007 with a six-month authorization to counter al-Shabab, a militant anti-government group. Although initially a marginal peacekeeping force of privately trained Ugandan soldiers, AMISOM has since expanded in size and in scope of mandate, and is now comprised of an estimated 22,000 troops from Uganda, Burundi, Ethiopia, Kenya, Djibouti, and Sierra Leone. Unlike typical peace-support missions, AMISOM has taken the lead role in the counterinsurgency campaign, filling in as a de facto army until the Somali National Army (SNA) is strong enough to counter the jihadi group on its own.

“Somalia is like cleaning a pig,” one Ugandan AMISOM colonel told Foreign Policy. “You clean it, and it gets dirty.” He compared Somalia to Afghanistan. If the coalition in Afghanistan left, he argued, the Taliban would easily take the country back. The same was true for Somalia. Whether or not the colonel’s assessment is accurate, the extension of AMISOM’s mandate, now with more ambiguous language about an exit date, underscores the SNA’s grim situation.

Somalia, which Transparency International has rated the world’s most corrupt country for 11 years running, represents the worst of modern war and the international state-building economy. But Somalia wasn’t always a war zone. In the first decade after the British Somaliland protectorate and the U.N.-administered former Italian Somaliland colony gained independence and unified in 1960, the Somali Republic was a stable, relatively prosperous democracy. As politicians stoked nationalist sentiment in the name of a Greater Somalia, the country sought to build a formidable army, known locally as “The Lions of Africa,” with Soviet assistance. At the time, military academies in the country were so well resourced they had tanks to spare for practical training.

These days, after decades of military dictatorship, failed foreign escapades, civil war, and armed insurgency, there’s not even adequate funding for essentials like radios and protective gear. Many SNA soldiers operate in flip-flops.

Meanwhile, a conglomeration of countries are paying each other, and each other’s companies, ostensibly in support of Somalia as it rebuilds a national army. Each has its own military models that differ in ways big and small, from the way that soldiers salute to the chain of command. More significantly, each has different funding streams, various internal alliances, and broader strategic agendas.

Turkey has its own military academy. Qatar has one as well. The United Arab Emirates’ training facility shut down in April, a proxy in the Persian Gulf dispute. The Egyptians and the Sudanese are training officers. The British are conducting training in their own center, south of Mogadishu, in Baidoa. And the United States, as well as private U.S.-based security firms, are working with the Danab special operations forces on Baledogle air base. The United States used to provide funding for fuel and food for the SNA proper, but suspended that support in December because of fraud.

The SNA “could be highly effective,” said a foreign advisor to the Defense Ministry, who has worked in more than 20 countries and wishes to stay anonymous. “Turning the SNA into an army here, while difficult, is doable,” he added. But, he argued, “the way we’re doing it is impossible.”

After so many attempts at state-building and training national armies—not least of all in Iraq and Afghanistan—it seems as if the international community is following a failed blueprint. “The West has trained the three most abysmal armies in the world: the Iraqi Army, the Afghan Army, and Somali Army,” said Stig Jarle Hansen, an associate professor of international relations at the Norwegian University of Life Sciences.

None of this bodes well for the Somali people, and suggests that, even if AMISOM eventually follows through on its announced intent to leave, there will be private security firms, peacekeeping missions, and mercenaries in the country for the foreseeable future.

The dire straits of the SNA and the reason for AMISOM’s extension became immediately obvious during a trip through the men’s surgical ward at Mogadishu’s Madina hospital, which is filled with wounded soldiers.

There I met 48-year-old Abdullahi Awayle Ali, who joined the army after he was arrested by al-Shabab. His relatives negotiated his freedom, but Ali was worried that he’d get stopped again. He decided he needed to get out of his village. He joined the SNA and, after training, was made an officer. Ali was stationed in rural Buurdhuubo district, southwest of Mogadishu, close to the Ethiopian border, where, early one morning in 2016, al-Shabab attacked his compound. The troops managed to hold off the advance, but not before the SNA guard at the front gate was killed.

Amid the ongoing battle, Ali ran to retrieve the corpse. A bullet pierced his leg in the process. Ali made it safely back to the compound but he was badly injured. He was also stuck. Buurdhuubo is a remote base, and al-Shabab controlled the surrounding area. The soldiers could defend its main gates, but to beat a path through the opening to the nearest town would mean almost certain death.

For nearly a year, the soldiers focused on their own survival, not on routing al-Shabab. Ali, along with his fellow troops, was marooned, his thigh festering. “The SNA didn’t have the ability to do anything,” he said. Everyone, it appeared, was doing what they could. His early anger dissipated over the 300-plus days it took before they were able to leave the base; a nearby Ethiopian convoy with enough armored vehicles to spare organized an evacuation.

Ali and his fellow soldiers were ill-equipped and disorganized. Many SNA soldiers who’ve completed training often lack the skills to correctly hold their weapons, if they’ve managed to get their hands on one. The European Union Training Mission, for example, does not train with firearms. (Its officials did not respond to a request for an interview about their training.)

It is difficult to get a clear answer about who provides weapons to the SNA. The United States, United Kingdom, and the EU don’t give out lethal equipment. The Gulf states and Egypt openly sell or distribute weapons, flying or shipping them into Mogadishu, where they are meant to be stored at an armory before they are registered and then sent to various SNA posts, but guns and ammunition tend to get distributed to clans or sold on the black market instead. If there isn’t any political gain in getting the supplies from Mogadishu to Baidoa, for example, then no one will pay for them to get to their intended destination.

Ali is comparatively lucky; the government is funding his hospital stay. He’s getting three meals per day and treatment for his massively swollen leg. The SNA is giving his family food assistance as well, he says. Still, it’s a large sacrifice to be made by someone whose last paycheck of $100 arrived months ago—from the United Kingdom, one of the many countries providing intermittent stipends to the SNA soldiers.

Without streamlined support it’s hard to see how people like Ali can be part of this institution—indeed, it’s difficult to see how the SNA is an institution at all. Complicating matters further, it is not uncommon for a family to have members in both the army and al-Shabab. Ali’s son was a member of al-Shabab, having joined after they offered him a mobile phone. Ali disowned his son, but the son was then motivated to quit on his own after al-Shabab killed his mother, Ali’s wife. Now he’s in the SNA.

“I have no doubt that al-Shabab have infiltrated the Federal Government of Somalia as double agents,” former spokesman for the Ministry of Internal Security Abdulaziz Ali Ibrahim said in an interview with FP. Such infiltration of the security sector creates serious problems.

At least 21 people were killed and an unknown number injured in Mogadishu in July as al-Shabab was able to get through a number government checkpoints to attack targets including a popular hotel and the Interior Ministry compound. Last month, the office of the deputy director of the National Intelligence and Security Agency was raided, allegedly by men with ties to al-Shabab. Members of the group infiltrate the SNA and NISA, often donning uniforms to strike checkpoints, training camps, and soft targets.

According to the to the Defense Ministry advisor, it’s an open secret that members of the government—and even members of the international community—will hire al-Shabab to kill or intimidate their political rivals. A prime example was the attack last year on the Dayah Hotel, where numerous politicians were staying. Twenty-eight people were killed and 43 were injured in the attack, for which al-Shabab claimed responsibility.

The inability to articulate who and what exactly is al-Shabab is one of the main security problems in Somalia. “Have you seen anyone in Somalia define al-Shabab?” a prominent businessman asked. “You have to be able to define who the enemy is in order to defeat them,” he argued.

The businessman’s comments get to the heart of what so-called Western development partners don’t publicly acknowledge: al-Shabab is ostensibly one with the population, including with the government. While some of its members reside on military bases, many live in cities, towns, and villages. They are not a separate entity but part of the overall social fabric. This makes putting together a “national” army difficult.

Most of al-Shabab’s activity is domestic. When they do stage international attacks, the targets are generally in countries that are part of AMISOM or that otherwise meddle in Somalia. The 2013 siege at an upscale shopping mall in Nairobi that killed 67 people is one such example. The attack killing 148 mainly Christian students at Garissa University in northern Kenya in 2015 is another.

Within Somalia, al-Shabab is far more prolific; bombings on government buildings, hotels, restaurants, and sports stadiums are weekly occurrences. More than 500 people were killed on Oct. 14, 2017, when twin vehicle bombs detonated at a busy intersection during rush hour on a work day. Buses of children were blown up and a whole city block, lined with new homes and offices, was leveled in an instant. While al-Shabab has still not formally claimed responsibility for the massacre—since doing so would likely turn too many people against the group—they’re the only credible perpetrator.

Somalia has massive geographic importance. It connects Africa to the Middle East and possesses the African mainland’s longest coastline, stretching nearly 1,900 miles. Each year, billions of dollars’ worth of goods pass through its waterways en route from Asia and the Middle East to Europe. The country has a wealth of largely unexploited natural resources, including uranium, iron, and copper—as well as oil potential. This is an incentive for the international community to stabilize the country and rid it of radicalism.

The United States has provided more than $900 million in bilateral assistance to AMISOM, and an additional $720 million to the U.N. Support Office in Somalia, that works with the army. By 2016, the EU was contributing about $23 million per month to AMISOM and spending about $35 million per year on the training mission. The funding is capricious, though: In February, the German government announced it would be withdrawing its support from the EU training mission, citing a lack of progress. Money from the Gulf states is tied to their separate geopolitical crisis, in which Somalia is both bit player and big pawn. Turkey, meanwhile, remains a steadfast partner because Somalia is its largest humanitarian mission.

It took four years of dogged fighting to wrest control of Mogadishu back from under the under the complete, public influence of al-Shabab. The West still refused to commit its own troops but funneled money to AMISOM while turning a blind eye to the rampant human rights abuses, especially sexual assault, committed by its forces—another element that aids the jihadi group’s propaganda mission.

The facts that AMISOM hasn’t fully flushed out al-Shabab, and that the SNA remains so incapable after so many years, have fueled rumors—even among some educated, worldly Somalis who don’t support al-Shabab—that such chaos is in fact the Somali federal government’s end goal, allowing foreign forces to remain on the ground and in control while government officials take their share of the spoils.

A much-heralded agreement made in London in April 2017 established a “national security architecture” for the first time, but none of its milestones are close to being met. Hussein Sheikh Ali, the founder of the Hiraal Institute, a security think tank in Mogadishu, says there is no “real political will” to implement the security architecture because so many of the people are benefiting from the status quo and are nervous about ceding power to the more federalist structure designed in London. No one trusts anyone.

“The Somalis lost the war and the world is trying to pander to their every need to show to their home nations they are making progress; meanwhile, [Somali government officials] are laughing all the way to the banks and meanwhile secretly supporting al-Shabab,” said an SNA trainer in an email, stressing that government figures “don’t want to solve any problems because they want the money to keep coming.”

One of the concerns with the extended AMISOM mandate, or any externally funded security protection, is that the Somali government will have more incentive to extend the status quo and not invest in the army. “Building the SNA is more of a priority for the international community than it is for Somali politicians,” said E.J. Hogendoorn, the International Crisis Group’s deputy program director for Africa.

Those perverse incentives have contributed to systemic corruption in the SNA. Indeed, the flailing army feeds off the disorganization and greed of the countries and companies supporting it, creating room for al-Shabab’s infiltration. Many Somalis are now starting to call for a reconciliation with the extremist group, while Western governments say they do not engage with outfits they’ve branded as terrorists. The result will be band-aid armies like AMISOM or a country overrun with mercenaries.

“You can buy an army here,” the advisor to the Defense Ministry told me bluntly. “Collectively, we as the international community have been supporting nothing but a criminal patronage network for years.”

Editor’s note, April 9, 2019: A sentence regarding al-Shabab’s influence and telecommunications surveillance in Somalia that appeared in the original version of this article has been removed, and the article has been updated.