People inspect damage at a site hit by Saudi-led air strikes in the al Qaeda-held port of Mukalla city in southern Yemen April 24. (Reuters)

Al-Qaeda in the Arabian Peninsula (AQAP) went “on the run” 10 days ago as UAE-supported military forces closed in on the city of Mukalla, AQAP’s de facto capital in eastern Yemen. Saudi state media celebrated a mass annihilation of fleeing AQAP fighters. In reality, the evidence from the ground was more complex. According to my sources in and around the city — borne out by other reporting — AQAP conducted a tactical withdrawal following negotiations with local intermediaries. It remains a coherent organization.

This “liberation” of Mukalla from al-Qaeda rule raises awkward questions. First, how was AQAP able to facilitate a graceful exit, such that it can regroup and bide its time to return? Second, and more fundamentally, how has AQAP continued to spread its influence despite its undoubted losses sustained during years of drone strikes? The answer lies in examining and understanding AQAP’s evolving “Robin Hood” tactics.

During my most recent research trip to eastern Yemen late last year, I was struck by a meeting I had with three leading community members from Mukalla, which had been overrun by AQAP since April 2015. Long into the night I listened to their litany of complaints against AQAP, linked to the new restrictions afflicting their familiar daily routines. When I suggested continuing our discussion the next day, one of them was quick to apologize; he had to rush to a meeting with AQAP commanders. He shrugged off this seeming contradiction by explaining that there was a water problem in his village, and AQAP had promised to fix it. His companion chipped in with news of a long-standing land dispute that AQAP was helping to settle. Despite popular dislike of the organization, even its detractors grudgingly acknowledged that AQAP was approachable, had some sense of justice and got things done.

In the West, counterterrorism is framed in terms of security: how to combat (read “kill”) militant jihadist fighters. But the real problem is not so much the jihadists, ready and even eager to die for their cause. It is AQAP’s notable ability to create safe havens in which extremism can flourish by establishing relationships among populations that rarely share their vision but nevertheless tolerate them. These populations abide AQAP because the terror group helps to support those communities.

Given the importance of charitable work in Islam and the failure of several Middle Eastern dictatorships to provide broad welfare benefits, it is not surprising to see organizations fill this need in the name of Islam. There has been some high-quality research into the services provided by Islamist organizations by scholars, such as Janine Clark, Carrie Wickham, Asef Bayat, Abdullah Al-Arian and others. The general interest, however, has tended to focus on the link between Islamists’ provision of social services and support for Islamist political parties. Some scholars have also looked beyond electoral politics to explore how social services can win broader “street power” for Islamists by showing them to be community protectors, as Melani Cammett argues for Lebanon’s Hezbollah or Steven Brooke for Egypt’s Muslim Brotherhood. More worryingly, and following the lightning rise to prominence of the Islamic State, several scholars, including Daveed Gartenstein-Ross, Will McCants, Megan Stewart and Aaron Zelin, have noted how terror groups have started to engage in social services as part of state-building enterprises.

While little quantitative evidence exists to measure the popular effects of such social programs, in Yemen at least, the evolving tactics of AQAP itself suggests that such programs do succeed in building tolerance for extremist groups, if not outright support.

The start of the Saudi-led coalition bombing campaign in western Yemen in March last year facilitated the resurgence of AQAP in eastern Yemen, from which it was able to strike out along key trade routes in central and south Yemen. AQAP’s record of bank robbery, prison breaks, kidnapping, extortion, smuggling and lethal operations is well known. What is less well understood is how AQAP’s governance and public project model has evolved since its initial, aggressive attempt to construct an Islamic “emirate” in central southern Yemen in 2011 to 2012, which ultimately failed. Over the past year, AQAP had been able to pose as a local protector-savior rather than an overlord in Mukalla.

Although AQAP still carried out periodic Sharia punishments, such as execution for adultery or sorcery and amputation for theft, its primary emphasis had shifted onto local power-sharing models accompanied by an energetic program of community development. To help fund this, it robbed the rich in the name of the poor. Three months ago, AQAP wrote to oil and telecoms companies in Mukalla, demanding large payments “in order to meet the needs of the people.”

To develop its positive image, AQAP articulated a community oriented hearts and minds campaign on the front page of a new jihadist newspaper, al-Masra, launched in January. The same month, AQAP launched a second new media outlet, Wikalat al-Athir, specifically to highlight its “good works,” which included: repairing schools, building roads, funding hospitals, connecting electricity and water, dispensing aid, mending fishing nets and solving land disputes. This campaign involved clever local branding. The works were undertaken by Ansar al-Sharia (Supporters of the Sharia) via local affiliates with friendly names such as the Sons of Hadramawt, or the Sons of Abyan. Exploiting its local knowledge and tribal ties in large part explains why AQAP has not had to yield ground to the “Islamic State” in Yemen.

Recent military operations aimed at checking AQAP expansion in Yemen’s south have yielded valuable insights into how it gains traction. For example, AQAP took its injured fighters to Ibn Sina’ hospital in Mukalla following U.S. airstrikes on an AQAP training camp on March 22. The hospital was indebted to the group following previous donations of money and equipment. AQAP later thanked and rewarded hospital staff by handing out cash envelopes.

AQAP’s campaign is perhaps most powerfully seen in a statement it released on April 22, as coalition forces amassed in the deserts of Hadramawt for imminent attack. The announcement warned locals against signing up with coalition forces, which it cast as outsiders aiming to sow civil war, occupy their land and steal their resources. What is striking is the way in which AQAP aimed to convince locals by drawing on its track record of good governance, rather than relying on religious arguments or aggression. The statement read more like a plea than a threat. It emphasized the development, stability and security AQAP had brought to coastal Hadramawt.

This stability sits in stark contrast with Yemen’s other regions devastated by war. Less than two months ago, AQAP organized a street festival in Mukalla, complete with an ice cream eating competition, Koran quiz and sing-along for the children. The crowds were wowed by poetry, Arabia’s oldest and most revered art form, and performances in which fighters demonstrated choreographed combat moves. Even AQAP’s recent withdrawal from Mukalla has enabled it to claim the moral high ground for saving the city from imminent destruction.

So what is the long-term solution to AQAP? One option, and the one too often used in isolation, is to kill. “There are many ways to end the AQAP problem in Yemen, and all involve splattering their brains on the ground,” noted prominent Yemen commentator Haykal Bafana recently on Twitter. There is a certain grim truth to this. The trouble is that military operations kill people, not ideas, so the benefits tend to be short-lived.

Breaking the long-term cycle of terrorism requires a full-spectrum approach that empowers and includes local communities. Many Western-funded development projects in Yemen have tended to work using a top-down approach, within the frameworks of a rampantly corrupt kleptocracy, thereby perpetuating it and discrediting Westerners in the process. As a result, whole communities have been marginalized, missing out on not just development but also aspirations to justice and meritocracy. However grim its vision, al-Qaeda has understood this. It learns and adapts. Expelling AQAP from vulnerable communities requires a deeper understanding of its strategy and perhaps some learning and adapting, too.

Elisabeth Kendall is a senior research fellow in Arabic and Islamic Studies at Pembroke College, University of Oxford.