ATaliban prisoner named Mohammed Nazir is brought into the warden’s office here in ankle cuffs and seated on the couch next to me. He is wary but articulate about what ails his country. “The major problem is our justice system. It is corrupt,” he says. And he’s right.

The Taliban’s greatest asset has been its ability to provide quick justice in a country shattered by war and corruption. It was the recruiting card for Afghans such as Nazir, a 31-year-old mullah with a long black beard and sparkling white teeth, who was convicted of helping plant roadside bombs.

Here lies the biggest challenge for America as it begins to reduce forces in Afghanistan. The United States must help the Afghan government provide justice and other basics of governance in the Pashtun areas where the Taliban took root. An old Pashtun proverb says that “a country without law is a jungle,” and if the jungle remains, the Taliban wins.

I had a glimpse this week of some new U.S. efforts to fill this vacuum of governance, in visits to Khost near the eastern border and Baghlan province in the far north. I came away impressed by these projects but wishing they had begun years ago, at the beginning of the 10-year war in Afghanistan. Now, with American patience exhausted and U.S. combat power on the decline starting this month, there may not be enough time.

The trip to Khost was arranged by Brig. Gen. Mark Martins, who heads a new Rule of Law Field Force. He’s one of the Army’s stars — West Point, Rhodes Scholar, Harvard Law and part of Gen. David Petraeus’s inner circle in Iraq and Afghanistan. To visualize the justice problem, Martins displayed the 88 Afghan districts without government prosecutors and the 117 without judges. The map is very similar to that of the Taliban’s strongholds.

It’s clear in Khost that the United States has some worthy Afghan allies, as well as antagonists such as Nazir. The most impressive colleague was Lt. Mohammed Zareem, a local police commander who was the hero of a May 22 assault. Four Taliban fighters wearing suicide vests had seized a police building and captured four policemen. Zareem and a five-man Afghan police team, partnered with three U.S. soldiers, rescued the hostages, killed the suicide bombers and defused a car bomb outside. Zareem carried a wounded American sergeant away from the building under fire and was shot twice. “That was my job,” he says.

You often hear stories about poor performance by Afghan soldiers and police, but Zareem’s tale made me think again. Working closely with U.S. mentors, such as Col. Chris Toner, the commander of U.S. forces in Khost, the Afghans are performing better.

In Baghlan, I saw another attempt to fill the local governance gap. Lt. Gen. David Rodriguez, the deputy to Petraeus, was making a farewell tour of the north. In the village of Gaji, he met a former Taliban fighter named Noor ul-Hak, who joined the “reintegration” program and now heads a nearly 300-man unit of a new program called the Afghan Local Police.

The scene was something out of a counterinsurgency manual. The 6-foot-5 Rodriguez sat on the floor next to the spindly former insurgent, flanked by U.S. Special Forces soldiers who have been living rough in this valley, mentoring Hak and the other ALP recruits nominated by local tribal leaders. With their bushy beards and faces weathered by the sun, the Special Forces operatives might be mistaken for tribesmen themselves.

The enemy out here is the corrupt and incompetent Afghan government as much as the Taliban. “The government is supposed to solve problems, but it’s the opposite; they create problems,” Hak said, with Rodriguez nodding assent. Indeed, this very week, he had pushed the Afghan interior minister to fire the Baghlan provincial chief of police. The hope is that the ALP, which will eventually have 100 branches, can work through tribal elders to build local security where the government can’t or won’t. But it’s a tricky business. Hak’s tribe may be pleased to see him wielding power with American support, but other local tribes are not.

Rodriguez, who’s finishing his second tour here and, like Petraeus, will be leaving Afghanistan this month, says his main regret is that the United States didn’t implement its current strategy faster. “When I first got here, I didn’t know 10 percent of what I needed,” he explains. “We poured money in here without the proper governance systems.” The United States has learned lessons, but late in the game.