Somaliland is a success story in a part of the world where those are rare. For 27 years, the self-declared state—with little outside assistance—has defied the odds. In contrast with Somalia, from which it declared its independence in 1991, Somaliland has enjoyed years of relative stability and democratic governance.

The autonomous but unrecognized Republic of Somaliland has also eradicated piracy from its shores and thwarted the jihadist group al-Shabaab’s expansion within its borders. Somalia hasn’t managed any of this, despite the billions of dollars expended by the international community over nearly two decades.

Rather than spending money it has never had on advanced weaponry, drones, and a large unwieldy army, Somaliland has instead focused on the two things that always form the backbone of successful counter-terrorism and counter-insurgency: good governance and reliable human intelligence. The two are almost always linked.

Good governance guarantees buy-in and cooperation from communities whose members are on the frontlines of the war against extremists. The government of Somaliland recognized this early on when it developed its anti-piracy program.

Those anti-piracy efforts denied maritime gangs access to its shores and coastal waters at a time when pirates based in Somalia and Puntland, a semiautonomous region directly south of Somaliland, were attempting to hijack vessels on an almost daily basis (40 were successfully stolen in 2008). In Somalia and Puntland, pirate gangs had free rein in many areas and became mainstays of the local economies.

The overall cost of Somaliland’s anti-piracy program was less than $500,000 in 2010, when, during the same period, the U.S. and its international partners were sinking hundreds of millions off the coast of Somalia. These international efforts did reduce incidents of piracy but they did little to combat the problem on the ground in Somalia and Puntland, where many pirate gangs simply shifted from hijacking to kidnapping. Some pirates went on to join al-Shabaab.

In contrast, Somaliland’s program dealt directly with the problem by preventing pirates from establishing ties to local communities. The government of Somaliland ensured that coastal areas played a leading role, becoming its eyes and ears. At the cost of a few cell phones, Somaliland established a highly effective early warning system that allowed communities to report suspicious activity and provide the very local and immediate intelligence that is critical to fighting piracy.

Somaliland’s government learned a great deal from its anti-piracy efforts and applied those lessons to its equally successful counter-terror operations. Just as with the fight against pirates, community engagement remains central to the battle against al-Shabaab. Somaliland does not rely on drones, military contractors, or any of the other expensive trappings of the counter-terror programs of its southern neighbors. Instead, the key element of its operations are the people it defends. The best intelligence, which is critical to fighting a group like al-Shabaab, is not produced as a result of coercion or payments. Instead, Somaliland pays for the information provided by its citizens by maintaining a government they can participate in and rely on—at least much of the time—to respond to threats to their communities.

By comparison, al-Shabaab remains a potent force in Somalia despite the billions of dollars spent trying to eradicate it. The U.S. government alone spends tens of millions annually on its counter-terrorism efforts in Somalia, where it relies on drones, Special Forces raids, dubious and poorly led militias, and military contractors to battle al-Shabaab.

In addition to American efforts and expenditures, the African Union Mission in Somalia (AMISOM) has deployed thousands of soldiers supplied with heavy weaponry and air support to combat al-Shabaab. Yet despite their overwhelming numerical and technological superiority, al-Shabaab persists and remains a highly capable foe.

The reason for this is that the leadership of al-Shabaab understands what all successful insurgent groups understand: predictability, reliable governance, and community engagement are critical to maintaining support. The governance that al-Shabaab provides is brutal but at the same time it is predictable and rarely arbitrary. The government of Somalia is slowly building its capacity to govern but still fails to provide its citizens—especially those living in areas away from urban centers—with the level of consistent security that al-Shabaab does.

This is evidenced by the fact that many Somalis actually seek out courts run by al-Shabaab rather than those operated by the Somali government. This is because al-Shabaab’s courts issue verdicts quickly, offer arbitration that is often in line with local customs, and are more capable of enforcing verdicts and arbitration. Even in the Somali capital of Mogadishu, al-Shabaab-linked clerics and qadis run a parallel justice system that is favored by some residents.

Al-Shabaab understands exactly what the government of Somaliland understands: that consistent governance is fundamental to maintaining the support of communities. The support it’s gained as a result is exactly what an insurgent group needs to persist and even defeat a better-armed adversary. But in Somaliland’s case, that support has fallen behind the democratic government, which has allowed the authorities to consistently thwart and defeat terrorists. This is the only weapon that will work in the war on terror over the long term: good governance in which citizens can participate and take pride.

Michael Horton is a foreign policy analyst who has written for numerous publications, including Intelligence Review, West Point CTC Sentinel, The Economist, The National Interest, and The Christian Science Monitor.