Gen. Keith Alexander

“We need to recognize that those who are working to protect our nation are not the bad people,” Gen. Keith Alexander, who led the National Security Agency for nine years, said in a recent interview. Above, he testifies before a House panel last year. (Olivier Douliery, Abaca Press/MCT / June 18, 2013)

FT. MEADE, Md. — In nearly nine years as head of the nation's largest intelligence agency, Gen. Keith Alexander presided over a vast expansion of digital spying, acquiring information in a volume his predecessors would have found unimaginable.

In Iraq, for example, the National Security Agency went from intercepting only about half of enemy signals and taking hours to process them to being able to collect, sort and make available details of every Iraqi insurgent email, text message and phone-location signal in real time, said John "Chris" Inglis, who recently retired as the NSA's top civilian.

The overhaul, which Alexander ordered shortly after taking leadership of the agency in August 2005, enabled U.S. ground commanders to find out when an insurgent leader had turned on his cellphone, where he was and whom he was calling.

"Absolutely invaluable," retired Gen. David H. Petraeus, the former U.S. commander in Iraq, said in an interview as he described the NSA's efforts, which led to the dismantling of networks devoted to burying roadside bombs.

Alexander "sped the place up," Inglis said.

But something else seems likely to shape the legacy of the NSA's longest-serving director, who retired Friday: something that Alexander failed to anticipate, did not prepare for and even now has trouble understanding.

Thanks to Edward Snowden, a former NSA contractor, the world came to know many of the agency's most carefully guarded secrets. Ten months after the disclosures began, Alexander remains disturbed, and somewhat baffled, by the intensity of the public reaction.

"I think our nation has drifted into the wrong place," he said in an interview last week. "We need to recognize that those who are working to protect our nation are not the bad people."

When Snowden's disclosures began, Alexander and his deputies knew they were in for a storm. But they felt sure the American public would be comforted when they learned of the agency's internal controls and the layers of oversight by Congress, the White House and a federal court.

"For the first week or so, we all had this idea that we had nothing to be ashamed of, and that everyone who looked at this in context would quickly agree with us," Inglis said.

Instead, polls show, many Americans believe that the NSA is reading their emails and listening to their phone calls. A libertarian group put an advertisement in the Washington transit system calling Alexander, a 62-year-old career military officer, a liar. U.S. technology companies are crying betrayal.

The ease with which Snowden removed top-secret documents also embarrassed an agency that is supposed to be the first line of defense against cyberattacks.

In July, Alexander offered to resign, but the White House turned him down, he said. He didn't think holding other senior officials accountable would be right because a massive theft of documents by a systems administrator could not have been foreseen, he added.

The NSA has since implemented 42 changes to security procedures aimed at preventing a recurrence. In a system akin to that used with nuclear missiles, two people will be required for the sort of bulk movements of data Snowden handled, so each can watch the other.

Alexander blames the vehemence of the public reaction on what he views as sensational and misleading reporting, amplified by critics who want to radically curtail the agency. He sees a fundamental difference between the intelligence abuses uncovered by Congress in the 1970s — including revelations that the NSA spied without warrants on domestic dissidents — and the programs exposed by Snowden.

"What the Church and Pike committees found" nearly 40 years ago was "that people were doing things that were wrong. That's not happening here," Alexander said, referring to the panels headed by Sen. Frank Church (D-Idaho) and Rep. Otis Pike (D-N.Y.) that examined intelligence-agency activities in that era.

Outside reviews, including one released in December by a presidential task force, he said, found that "lo and behold, NSA is doing everything we asked them to do, and if they screw up, they self-report."

The task force reported it found "no evidence of illegality or other abuse of authority for the purpose of targeting domestic political activity." But it also noted "serious and persistent instances of noncompliance" with privacy and other rules. Even if unintentional, those violations "raise serious concerns" about the NSA's "capacity to manage its authorities in an effective and lawful manner," the report said.

Alexander's world view reflects a career in the national security bubble, said Michael German, a former FBI agent now at the Brennan Center for Justice, a civil liberties organization in New York.

"When you're the good guy and you're on the side of truth and democracy and the American way, anything that is an impediment to you is naturally bad and needs to be overcome, even if it's the law," German said.