In many ways, Charkh seems like a typical rural Afghan district. With little development or industry to speak of, its population of 48,000 ekes out a living mostly from farming. Poverty is common; those who can find better jobs elsewhere leave and send money back to support their families. But a closer look at Charkh reveals a divergence from what one may expect of an average Afghan district. Administrators there are widely seen as fair and honest, making them outliers in a country consistently ranked among the world’s most corrupt. Locals say there is remarkably little crime. Disputes among neighbors or families are rare, and when they arise, the district governor or judge quickly settles them. A health official regularly monitors clinics to make sure that doctors and nurses are present and that medicines are stocked. Across the district’s schools, government teachers actually show up, and student attendance is high—an anomaly in a state system where absenteeism is rife.

On paper, Charkh’s surprising success could be interpreted as evidence of how the U.S.-backed administration of President Ashraf Ghani has finally extended a semblance of good governance beyond the capital of Kabul. But in fact the Afghan government deserves no credit for Charkh; the district is currently governed by the Taliban. The de facto local authorities, from the mayor to the town’s only judge, come from the Taliban’s ranks, and ordinary bureaucrats, such as teachers and health officials, have been vetted and selected by the insurgency—even though Kabul still pays their salaries.

Despite the near doubling of U.S. troop levels and a spike in airstrikes over the past year, the Taliban retain significant influence in vast swaths of rural Afghanistan and are working assiduously to out-govern Ghani’s internationally recognized National Unity Government. The idea that the Taliban are now striving to provide good governance might strain credulity, given the draconian cruelty of their rule from 1996 to 2001. During those years, they banned women from school and work and executed young lovers in sports stadiums. Since the group’s overthrow in 2001, its brutal attacks have killed tens of thousands of Afghans. As recently as 2009, the Taliban were still killing teachers, burning schools, and attacking aid workers.

Today, however, the Taliban are seeking to present themselves as a legitimate political movement able to administer services and govern the country. As U.S. and Afghan forces pull back to protect major cities—as part of Washington’s new strategy—the Taliban are filling the vacuum. They are no longer just a shadowy insurgency; they are a government in waiting.

To understand the Taliban’s puzzling turnaround, one has to return to 2014. The withdrawal of tens of thousands of international troops that year presented the group’s leaders with both risks and opportunities. They had, after all, faced similar circumstances before: In 1996, during the height of the civil war, they’d taken advantage of the virtual absence of any form of central authority to sweep to power. But this time, the Taliban leadership realized that instead of attacking government schools and aid projects, it could gain much more by co-opting them. In doing so, it could take credit for providing services and win over the local population.

What began with a gradual recognition that unbridled violence would hurt the Taliban’s battle for popular support grew into a sophisticated governance structure, including the management of schools, clinics, courts, tax collection, and more. Local Taliban members began to strike unofficial cease-fires with Afghan soldiers to de-escalate the conflict. Government soldiers would man checkpoints until the evening, after which the Taliban would assume those positions until dawn. This shift in Taliban strategy created a relatively peaceful—if uneasy—coexistence between the insurgency and the government in areas that had previously been among the country’s most volatile. “They were cruel before, but now they are trying to show a different face,” said a former Taliban commander in the northern province of Kunduz. “They have to show they can do everything the government can—but better.”

Taliban fighters and officials credit Mullah Akhtar Mohammad Mansour for this transformation. Mansour nimbly led the movement through a series of pivotal moments: the so-called surge that began in late 2009, when Washington sent in 33,000 more troops to turn around the failing war effort; Mullah Mohammad Omar’s death in 2013, which Mansour, as his deputy, strategically concealed for two years; the 2014 drawdown; and the resignation of several key deputies once Mansour formally assumed the role of emir—the Taliban’s leader—in 2015.

“Mansour totally changed our thinking: about governing, about peace, about everything,” one Taliban official in the southern province of Helmand said. Mansour transformed the Taliban from a scrappy insurgency to a shadow state. He consolidated the military and financial wings of the Taliban, attempting to move away from a system of patronage to one focused on building institutions. Mansour created a Taliban commission to investigate civilian casualties. He appointed Tajiks and Uzbeks to the Taliban’s rahbari shura, or leadership council, broadening the movement beyond its Pashtun base.

Mansour was preparing the movement for life after war. Rather than seeking outright victory, he was positioning the Taliban for a power-sharing deal. Mansour was a staunch advocate for the opening of a Taliban office in Qatar in 2013, cautiously steering the group toward a greater openness to talks.

In May 2016, the United States killed Mansour in a drone strike, but his vision lives on. Its primary advantage is the way it allows the Taliban to spread their influence without incurring the high body counts and low morale that result from pitched battles. When the Taliban have tried to seize district centers and major cities—including the northern city of Kunduz in 2015 and 2016—they have been swiftly pushed back by airstrikes and internationally backed ground offensives. So while they continue to periodically attack cities, as they did this past spring in the western province of Farah and in August in the eastern province of Ghazni, the Taliban now devote fewer resources to these operations and use them more to embarrass the Kabul government than to capture territory.

The Taliban’s new focus is on extending their control in a more subtle way. By relying on coercion and their reputation for providing fair (if harsh) justice, they have gained new footholds in village after village. As their influence grows in a given town, the Taliban gradually impose their rules on civilian life and recruit a force of civil servants—ranging from electricity bill collectors to health inspectors—to enforce them. The level of their presence varies from place to place, but even in cities ostensibly under government control, such as Kunduz and Lashkar Gah, the Taliban now tax businesses and adjudicate disputes.

Unlike the Islamic State, which attempted to create new parallel infrastructure in the territory it seized, the Taliban prefer to co-opt existing government services and aid projects. In an October 2017 interview via WhatsApp, the Taliban spokesman Zabihullah Mujahid explained the seeming contradiction involved in working with a state his organization was simultaneously fighting: “This is about meeting people’s needs. It’s not a part of the war.”

But it is, of course. The Taliban have realized that there’s no need to attack symbols of the state if you can instead capture their resources and redirect them to your aims. This process has been made much easier by most Afghans’ frustration with the widespread corruption that has crippled public services and made finding work so difficult. An estimated 80 percent of state teachers must pay bribes to get their positions, according to an audit Kabul released late last year. “The government could do nothing in the past 10 years,” said Jamal, a former teacher at the boys high school in Charkh’s district center. “The Taliban solved our problems right away.”

Jamal, whose name has been changed for his protection, was just a teenager when the insurgency came to his village in Logar province around 2007 and he fled to escape the fighting. But he struggled to find a job elsewhere, and he decided to return after his family assured him that security had improved since the Taliban had taken control. His old school principal recommended him to the group, which checked out his background. Once they were satisfied that he was not a spy for the government, local Taliban officials indicated their approval to village elders acting as intermediaries between the Taliban and government officials. The elders informed Education Ministry officials, who then appointed him to his post.

Though Jamal worked in a state school and the Education Ministry paid his salary, Taliban officials were in charge of his work and his environment. Taliban-appointed monitors, usually village elders or mullahs, take staff attendance and instruct school officials to dock the pay of absent teachers. They occasionally remove what they deem to be objectionable content from the curriculum—such as a culture textbook showing photographs of female police—and replace it with religious texts.

A similar system exists in clinics and hospitals, where Taliban-appointed monitors appear at random to ensure that doctors are present and to inspect medicine stocks. “My Taliban counterpart called me and said, ‘You have to have one extra surgeon in this district and an X-ray machine,’” said Farhad, a public health official in Logar’s provincial capital of Pul-e-Alam, whose name has also been changed. When asked how he felt about such demands, Farhad was matter-of-fact, saying, “They give orders, and we have to obey. We may not like their way of doing things, but at least we can say that it is much less corrupt.”

Officials in Kabul are reluctant to publicly acknowledge or discuss ground-level negotiations with the Taliban, and they often reiterate their obligation to provide services to Afghans—regardless of what side of the conflict they might be on. “People living under the control of the Taliban are not necessarily Taliban themselves,” said Wahid Majrooh, a spokesman for the Ministry of Public Health. “The Ministry of Public Health is committed to providing health services to all Afghans.” While the ministry has no official policy on whether or how its employees should deal with the Taliban, he said that in “specific cases where health workers face challenges from insurgents, they solve the issue through community elders.”

No one can say for sure how much of the country the Taliban administer. Estimates of territorial control are hotly disputed. Operation Resolute Support, the NATO-led training and support mission, estimates that the insurgency influences or controls 14 percent of the country’s districts while the government controls 56 percent and the rest is contested. In contrast, a BBC study released in January estimated that the Taliban were “openly active” in 70 percent of the country’s districts.

Terms such as influence and “openly active” are difficult to visualize. The Taliban’s strategy defies zero-sum notions of control. An accurate map of Taliban influence would show most major district centers and cities encircled. An hour’s drive in any direction from Kabul will put you in Taliban territory. There may not be a Taliban flag flying, but everyone knows who is in charge. The Taliban make and enforce the rules; they collect taxes and decide how much of a presence the government can retain.

During the troop surge, international forces focused on an ink spot strategy: establishing control in district centers and aiming to win Afghan hearts and minds by providing aid and services. Government influence would then spread outward to connect to other state-controlled areas. The hope was that if the government could connect enough of these areas, it would amass enough support to turn the tide against the Taliban. With the drawdown of international forces, the opposite has happened: The ink spots have gotten smaller and less connected. The United States has abandoned counterinsurgency, while the Taliban are now using good governance to win civilian support.

The Taliban officials I have spoken to recently claim not to be seeking outright victory but a peace deal, and their method of governance seems to support this claim. Helmand province in southwestern Afghanistan offers the best example of how this process works. The Afghan government now estimates that the Taliban control 85 percent of Helmand, and locals refer to the northern town of Musa Qala as the Taliban’s capital. As elsewhere, Taliban rule relies on cooperation with the Afghan government.

During a visit to the provincial capital of Lashkar Gah, Hayatullah Hayat, the former governor of Helmand, displayed a binder full of letters from Taliban officials, many requesting the government to provide clinics and development projects. When asked why he entertained requests from an insurgency that his government was at war with, Hayat dismissed the Taliban’s staying power. “They can control these areas through violence, but they cannot provide real government. They have no capacity and no vision,” he said. “Afghans know it is really the government providing these things.”

Cooperation is uniquely bureaucratized in Helmand. Last February, representatives from the Taliban’s education commission and the government’s provincial department of education signed a 10-point memorandum of understanding outlining their respective responsibilities for providing education. Group pictures from the signing surfaced on Twitter, with black-turbaned Taliban members, their faces partially covered, sitting cross-legged alongside their government counterparts.

The agreement stated that all schools are government property but that it is the Taliban’s responsibility to protect the schools and their staff. Both sides pledged to work together to reopen the schools that had closed due to the fighting in previous years. According to Daud Shah Sharafi, the central government’s provincial director of education, 33 schools, or more than a fifth of those that had been closed, have reopened since the agreement was signed.

Sharafi defended the agreement, which the Afghan security services criticized bitterly. “Of course the Taliban are using this agreement as propaganda to show how weak the government is,” he said. “But is it better for children to be in school or for there to be no school and nothing for them to do but join the Taliban?”

Local Taliban members had a different take. “People criticized the Taliban for being ineffective in the 1990s, but we never had this kind of aid money when we were in government,” a Taliban finance official said. “Look at what we could do with all of this international support if you put us in charge.”

To many, the idea of the Taliban being back in charge is a terrifying prospect. The Taliban have shifted some policy positions, but many old rules have been reinstated. While the Taliban now say they do not oppose girls’ education or women working in certain sectors, the reality is that in areas the group controls, girls do not go to school past puberty and women cannot leave the house without a male chaperone. Men must grow their beards, eschew modern dress for shalwar kameez, and attend mosque. Smartphones and televisions are officially banned, and although the rule is often flouted, getting caught results in a beating. Those convicted of spying for the government are executed. Many citizens live in constant fear. Afghans who can afford to do so leave for nearby cities where the government’s laws still hold sway. Yet even there they are not safe, as countless Taliban attacks in cities across the country illustrate.

To what degree are the Taliban winning public support? The answer is not clear-cut. Certainly some Afghans in rural areas provide active support to the insurgency; the movement heavily relies on civilians for food and shelter. Most Afghans are just tired of war, disillusioned and disgusted by the unending brutality committed by all sides. They don’t see the current government or Taliban as an ideal option, but decades of upheaval and chaos have taught them that their preferences matter very little to the outcome. “We surrender to whoever is there. When the mujahideen came, we surrendered. When the [Hamid] Karzai government came, we surrendered. If the Taliban come, we surrender,” said another teacher from Logar. “This is how we survive.”

In August 2017, U.S. President Donald Trump announced a new strategy for Afghanistan, pledging “to fight and to win.” The strategy was heavy on air power and light on diplomacy and ultimately ill-suited to combat an insurgency so deeply intertwined with the population. Civilian casualties from airstrikes hit an all-time high in 2017. The United States dropped more bombs that year—with 14,000 troops on the ground—than it did in 2012 with almost 100,000 troops. Airstrikes were rarely followed up with attempts to establish government control, leaving most Afghans wondering what the point was.

Attempts at reforming the government, which would address the very causes of discontent that give the Taliban leverage, have foundered and are now only a marginal part of U.S. strategy. As a recent report from the U.S. special inspector general for Afghanistan reconstruction underscored, stabilization had largely failed and the United States “greatly overestimated its ability to build and reform government institutions.” The National Unity Government remains a fragile coalition nearly paralyzed by corruption and infighting. The only recent positive press the government has received was for orchestrating a three-day cease-fire with the Taliban over the Eid al-Fitr holiday in June.

In July, reports emerged that the Trump administration had abandoned its hopes of turning the tide of the war. The United States is now urging Afghan forces to further retreat from rural areas and instead focus their limited resources on protecting urban centers. The mission to build Afghan security forces has faltered, with the inspector general’s office reporting that force size has shrunk by about 5 percent over the past year. There are also signs that Washington is open to bilateral political talks directly with the Taliban, one of the insurgent group’s long-standing demands. In late July, Taliban officials claim to have met with Alice Wells, the White House’s most senior diplomat for South and Central Asia, which the State Department neither confirmed nor denied.

Direct talks are the only way to end America’s longest war, but it will be a long and tenuous process. Confidence-building measures, such as the Eid cease-fire, are important, but much more must be done, from creating a mechanism for formal talks to jump-starting the local peacebuilding initiatives that will build a foundation for a sustainable political settlement. Difficult questions remain, however, about the future of Afghanistan, particularly when it comes to democratic governance and human rights. While diplomats and pundits debate what a power-sharing deal with the Taliban might look like, a hybrid government is already taking over large parts of the country.

This article originally appeared in the Fall 2018 issue of Foreign Policymagazine.