Afghanistan's government is mired in a war against a 16-year insurgency that has forced the capital into virtual lockdown, ignited deadly protests, and compelled the head of state to retreat behind the barricaded walls of Kabul's presidential palace.

But off the battlefield, it is also waging a campaign against another evil: systemic government corruption.

President Ashraf Ghani has made tackling Afghanistan's entrenched culture of corruption a top priority as he tries to curb lawlessness and improve his administration’s tarnished image following a wave of deadly attacks that have dented public confidence in the government.

The latest major incident came when a tanker truck loaded with "military-grade" explosives detonated during rush hour in the capital on May 31, killing more than 150 people and injuring hundreds more in the deadliest act of terror in Afghanistan's post-9/11 history.

In an effort to turn the tide against insurgents, Ghani’s deeply unpopular and divided national unity government has specifically targeted the security apparatus, said to be a hotbed of corruption.

For years, analysts have regarded corruption as key to fueling grievances and channeling support to the insurgency. They say endemic graft remains an existential threat to the government and warn of the huge task Ghani faces in tackling misconduct in one of the world's most corrupt countries.

"Security-sector reform is the key for peace," Ghani said on June 6, following protests that turned deadly as public anger boiled over from a spate of bombings in the capital that killed more than 160 people over several days.

But the violence has also included a brazen Taliban attack on a military compound in Balkh Province in April that left 140 troops dead, a raid on a major hospital in Kabul in March that killed more than 50 people and was claimed by Islamic State (IS) militants, and twin blasts in July that tore through a demonstration in the capital by minority Shi'ite Hazaras, killing at least 80 people.

Ghani, who has ruled the country since a U.S.-brokered deal produced a sometimes shaky national-unity government in 2014, has sought to reform the Interior Ministry, which earned a reputation for being notoriously corrupt. He has recently overseen hundreds of dismissals of government employees for graft. And he has now drawn a bead on the Defense Ministry.

But the rising violence of the past year has heaped pressure on Ghani and his administration for demonstrable results.

Michael Kugelman, South Asia associate at the Woodrow Wilson International Center for Scholars in Washington, says there is a "clear connection" between government corruption and insecurity.

"State corruption strengthens Taliban narratives about an ineffective and illegitimate state and helps recruit more foot soldiers to its cause," he says, "especially when you promise swift justice and a regular paycheck."

In rural areas, where hard-line militants exert considerable influence and many people view government bodies as corrupt or unreliable, some Afghans still turn to Taliban courts to settle disputes. Such Shari'a courts routinely prescribe punishments that can include stoning and executions. The militants also match or better the salaries paid by the Afghan National Army.

"When an Afghan soldier, officer, or higher-ups engage in the sale of equipment, provide erroneous procurement reports, or are involved in contractual kickbacks, then that can lead to insecurity, negligence, and mismanagement," says Omar Samad, a former Afghan ambassador and government adviser.

Afghanistan has struggled with "ghost" soldiers on its military payrolls, with such salaries frequently ending up in the pockets of corrupt officers. The NATO-led mission in Afghanistan announced in January that it had finally stopped paying more than 30,000 such "ghost soldiers."

Meanwhile, weapons, ammunition, and fuel have been openly sold by Afghan officers, sometimes to the Taliban militants on the other side of the fight.

Ghani has implemented some of the anticorruption moves that emerged from the October 2016 Brussels Conference On Afghanistan, when the Afghan government agreed to draft and pursue an anticorruption strategy for the whole of government by 2017.

The president has also established a special court, the Anticorruption Justice Center (ACJC), to oversee major corruption cases.

And there are signs of progress.

In March, the Defense Ministry said it had dismissed nearly 1,400 employees over the past year for alleged corruption. More than 300 officials had been brought to justice, it said. The ministry also said it was reviewing more than 1,800 allegations of corruption in national defense structures, adding that nearly 170 cases had been referred to law enforcement agencies.

The biggest name among those officials was Mohammad Faqir, a former commander of the 215th Corps in Helmand Province, who was accused of misuse of supplies and rations, neglect of duty, and a lack of transparency in the use of fuel, food, and other supplies.

The anticorruption effort has spread beyond the security ministries. In May, Kabul Mayor Abdullah Habibzai said he had dismissed 180 staff members over a six-month period for alleged involvement in corruption.

In March, the ACJC convicted four Urban Development and Housing Ministry officials on charges of embezzlement and abuse of authority. Two were sentenced to 20 years in prison for embezzling more than $12.8 million, while two others were sentenced to seven years each. That same month, the ACJC sentenced the provincial council chief of Herat Province, in absentia, to 2 1/2 years in prison for abuse of authority.

Ghani also reopened the investigation into the Kabul Bank corruption scandal, a $900 million case that wrecked the country's largest bank and further shredded its international reputation. The president also sacked much of the administration of western Herat Province over allegations of corruption and incompetence.

The NATO mission noted that the government in Kabul had "increased will to respond to corruption" following the Brussels Conference.

But observers warn that there has been little evidence of far-reaching results.

"There is a lot of talk and pledging by the government, especially to the donors, and there are occasional dismissals from the lower ranks," says Samad. "But there are allegations of serious corruption at the higher levels, where patronage, nepotism, and influence peddling make it difficult to fight the darker side of corruption: bribery from the award of contracts, drug trafficking, and money laundering."

Anticorruption activists warn that bribery and related misconduct permeate all levels of Afghan society. Integrity Watch Afghanistan estimated that Afghans paid an estimated $3 billion in bribes in 2016.

Analyst Kugelman says Ghani has taken a personal interest in the need to combat corruption, and there have been some successes in the justice system and in the language of anticorruption legislation still awaiting approval in parliament.

"However, in a nation like Afghanistan, where the depths of corruption know no bounds and [the problem] is both structural and psychological, even a determined leader like Ghani will face many obstacles," Kugelman says.