But he added a caveat: “We are in the middle of war. It is very difficult to say that we are perfect at this stage.”

THE level of secrecy surrounding the agency has done little to assuage fears that it is simply a new version of the old secret police, with its own paramilitary force, high-end surveillance abilities lent by the Americans, and a mandate to monitor and detain its own people.

The agency’s record is littered with documented cases of torture and other abuses. And though Mr. Nabil has set up an internal investigative unit and given Afghan and international human rights monitors access to the agency’s facilities, human rights advocates say substantive change requires public action and prosecutions, which have yet to materialize.

The N.D.S., meanwhile, eavesdrops widely on Afghans. During a presidential election crisis that nearly tore apart the government last year, Afghan officials said N.D.S. officers leaked incriminating recordings about efforts to fix the election in favor of Ashraf Ghani, the eventual winner.

Afghan and Western officials say they do not believe that Mr. Nabil played a role in leaking the tapes to the campaign of Abdullah Abdullah. Mr. Nabil was often praised by supporters of both camps for remaining relatively neutral through the crisis, and he and Mr. Ghani now meet daily.

But if factional divisions in the new government have posed a challenge for Mr. Nabil, they can hardly be more daunting than the one posed by the motley collection of former enemies that make up his own agency. Within the modern National Directorate of Security, old K.G.B.-trained hands work alongside the mujahedeen fighters they battled in the 1980s. And both groups share a distaste for colleagues brought in when the Taliban were in power.

Mr. Nabil maintains that those internal camps all lack strategic thinking, or even a shared sense of what they should be doing. Getting them all on the same page is “our biggest challenge,” he said.