WASHINGTON — In early September 2009, an email passed through an Internet address in Peshawar, Pakistan, that was being monitored by the vast computers controlled by U.S. intelligence analysts. It set off alarms. The address, linked to senior al-Qaida operatives, had been dormant for months.

Investigators worked backward and traced the email to an address in Aurora, Colo., outside Denver. It took them to Najibullah Zazi, 24, a former coffee-cart operator, who was asking an al-Qaida facilitator about how to mix ingredients for a flour-based explosive, according to law-enforcement officials. A later email read: “The marriage is ready,” code that a major attack was planned.

What followed was a high-speed cross-country pursuit in which the police stopped Zazi on the George Washington Bridge, let him go, and after several false starts, arrested him in New York. He eventually pleaded guilty to plotting to carry out backpack bombings in the city’s subway system.

That’s the kind of success President Obama seemed to be referencing Friday when he defended the National Security Agency’s (NSA) stockpiling of telephone-call logs of Americans and gaining access to foreigners’ email and other data from Microsoft, Google, Yahoo and other companies.

He said “modest encroachments on privacy” — including keeping records of phone numbers called and the length of calls that can be used to track terrorists, though not listening in to calls — were “worth us doing” to protect the U.S. The programs, he said, were authorized by Congress and reviewed by federal courts.

Obama acknowledged he had hesitations when he inherited the program from George W. Bush, but said he soon became convinced of its necessity. “You can’t have 100 percent security, and also then have 100 percent privacy and zero inconvenience,” he said. “We’re going to have to make some choices as a society.”

To defenders of the NSA, the Zazi case illustrates how the agency’s Internet surveillance system, which was set up over the past decade to collect data from online providers of email and chat services, has yielded results.

“We were able to glean critical information,” said a senior intelligence official, who spoke on the condition of anonymity. “It was through an email correspondence that we had access to only through PRISM.”

Veterans of the Obama intelligence agencies say the large collections of digital data are vital in the search for terrorists. “If you’re looking for a needle in the haystack, you need a haystack,” Jeremy Bash, chief of staff to Leon Panetta, the former CIA director and former defense secretary, said Friday on MSNBC.

Under the program, PRISM, intelligence officials must present Internet companies with specific requests for information on a case-by-case basis, showing that the target is a foreigner and located outside the U.S., a senior law-enforcement official said Friday.

If the NSA comes across information about a U.S. citizen during the search, it turns over that material to the FBI for an assessment, the official said.