A Boko Haram flag flutters from an abandoned command post in Gamboru deserted after Chadian troops chased them from the border town on February 4, 2015. (Stephane Yas/AFP/Getty Images)
Sarah Chayes is a senior associate at the Carnegie Endowment for International Peace and the author of “Thieves of State: Why Corruption Threatens Global Security.”

The writer, a senior associate at the Carnegie Endowment for International Peace, is author of “Thieves of State: Why Corruption Threatens Global Security.”

“He would have kept my house for himself if it wasn’t for the Taliban. They were quick and fair.” Thus did a resident of Kandahar, Afghanistan, recently describe Taliban justice to the New York Times.

Such words sound jarring to Western ears. Taliban courts may be called quick and brutal in Western accounts, but never quick and “fair.” Yet this observation provides some explanation for the emergence and staying power of extremist movements, from Afghanistan to the Middle East to Nigeria. If the global turmoil of the late 1980s was fueled by a liberty deficit, today’s extremist movements may well be exploiting a justice deficit.

The Kandahari’s words came as no surprise to me. I lived in Kandahar for a decade, and more than half a dozen years ago, I started hearing about people who submitted their disputes to the Taliban for adjudication. Ordinary people, people I knew. Unlike government courts, my neighbors told me, Taliban judges didn’t demand bribes. They did their work efficiently. And most important, they didn’t favor the rich and powerful over the poor and disenfranchised. They would issue subpoenas that even the well connected felt compelled to obey — for fear of retribution if they did not.

The problem, in other words, with the judicial institutions the United States and its partners were supporting in Afghanistan wasn’t that they were applying Western rules but rather that they were applying no rules at all — except the rule of the highest bidder and obedience to an increasingly criminalized elite.

A court official once brazenly told a friend who was trying to expel squatters from her family home that he knew her opponent’s claim to the house was fraudulent, since the “deed of sale” purportedly signed by her father was dated several years after the Soviets had killed him. “But your opponent has $5,000 to say it’s genuine,” the official informed her. “How much do you have to say that it’s not?”

When he was president, Hamid Karzai used to boast openly about his frequent, direct interference with judicial proceedings. A group of us working on rule-of-law issues at Western embassies and the international military headquarters would watch as, with a phone call, he got suspects released from pretrial detention, search warrants abandoned, case files buried. The Afghan government’s justice was at the service of a profoundly corrupt political order.

The same is true in most countries where extremist movements flourish. To ensure impunity for members of the ruling network, or punishment for the recalcitrant, Egyptian President Abdel Fatah al-Sissi directs key cases to military courts he can influence — just as Hosni Mubarak did in his administration.

In Central Asia, disgruntled young people no longer bother with pro-democracy groups, according to activists from several countries I have interviewed. Instead, they flock to the mosques. “The only people who talk social justice these days are the Islamists,” says George Washington University’s Marlene Laruelle, an eminent Central Asia scholar. “The argument they’re making is that the regime is corrupt and unjust because it’s secular. Such reasoning did not have much resonance in the past. Now it does.”

Militant puritanical religion, in other words, is presented as an inevitably more just an alternative to depraved secular rule.

In Nigeria, a movement in favor of sharia law swept across the north of the country 15 years ago, to the consternation of local Christians and Western observers. Fears of girls forced to wear veils, or adulterers stoned to death, abounded.

But now many Nigerians analyze the phenomenon differently. “People saw that the injustice was simply too much,” Yunusu Zakaria Ya’u, who heads a group working on budget accountability, told me in late 2013. “Corruption was everywhere, and no development. People thought that if they implemented sharia, corruption would be cleaned out. People will cut off their hands. But then they saw the criminals still had their two hands.” The criminals in government, that is. Disappointed, many turned to the more radical alternative embodied by Boko Haram, Ya’u said.

Of course, the extremists of Boko Haram, the Taliban or the Islamic State do not offer an attractive or sustainable alternative mode of governance. Still, their argument, initially at least, has proved compelling to many. If U.S. officials truly mean to address the underlying causes of extremism, along with combating its manifestations militarily, they should pay attention to justice and the rule of law.

That means more than just building courthouses or prisons or providing computers or technical training on behalf of judicial systems that can be bent to the service of abusive regimes. Of course, it’s harder to make an impact in most countries than it would have been in Afghanistan, where the United States had such overwhelming leverage for so long. But U.S. officials could raise the profile of rule of law at least to the same stature as religious freedoms or gay rights in bilateral exchanges with such countries. They could, when feasible, deploy some of the United States’ legal arsenal against corrupt foreign officials so as to change the incentive structure, at least a bit, by making it harder for them to enjoy the fruits of their abuse with impunity.