WASHINGTON (AP) — Top officials of the Bush and Obama administrations have repeatedly denied in recent years that the National Security Agency collected massive caches of phone and Internet data taken from millions of Americans.

Pressed during sworn testimony in congressional hearings and in other public settings, senior national security officials have said the government’s cutting-edge electronic monitoring is narrowly focused and preserves the civil liberties of ordinary Americans.

On Friday, Obama himself acknowledged the existence of the programs even as he gave the government’s standard rationale to ease fears that Americans’ privacy rights are being violated.

“By sifting through this so-called metadata, they might identify potential leads of people who might engage in terrorism,” Obama said during an exchange with reporters at a health care event in San Jose, Calif.

Obama’s comments marked the first time a U.S. president publicly acknowledged the government’s electronic sleuthing on U.S. citizens. They came in response to media revelations and published classified documents that detailed the government’s secret mass collection of phone and Internet communications.

When top officials in the Obama and Bush administrations have been asked in recent years whether U.S. citizens’ communications were swept up as part of government surveillance, they’ve often responded with swift, flat denials. Obama’s predecessor, George W. Bush, sidestepped what he described as a kerfuffle about his administration’s secret electronic intelligence-gathering efforts.

During a March 2006 appearance at the City Club of Cleveland, Bush described the NSA effort only as “a program that will enable us to listen from a known al-Qaida person and/or affiliate from making a phone call outside the United States in or inside the United States out, with the idea of being able to pick up quickly information for which to be able to respond in the environment we’re in.” He added: “I believe what I’m doing is constitutional, and I know it’s necessary. And so we’re going to keep doing it.”

His vice president, Dick Cheney, was blunter during a radio appearance that January, denying the government was engaging in domestic surveillance.

“This is not a domestic surveillance program,” Cheney told radio host Hugh Hewitt, adding that “what we’re interested in are intercepting communications, one end of which are outside the United States, and one end of which we have reason to believe is al al-Qaida-related.”

Technically, Cheney’s description of the program’s aim was accurate. His insistence that the Bush administration was not engaged in domestic surveillance is more debatable.

Reports that first appeared in the Guardian and the Washington Post indicate that the NSA pulls in phone records, though not the actual content of the calls, from its secret warrants allowing it to collect data from major telecom companies. The program’s aimed at detecting the calling patterns of terrorist suspects. A separate government program also collects massive amounts of data from at least nine Internet and electronic firms, pulling in everything from emails to photographs. Obama said Friday that the electronic data mining is not aimed at American citizens or inside the U.S.

Several top Bush administration officials who paraded before congressional hearings in 2006 adamantly insisted that the government was not engaged in mass data-trawling as part of its secret NSA programs.

After a controversial New York Times expose raised concerns about NSA targeting Americans’ phone records, the agency’s then-director, Michael Hayden, told a National Press Club audience in January 2006 that there was no effort to cast a wide net over communications data.

“This is targeted and focused,” Hayden said. “This is not about intercepting conversations between people in the United States. This is hot pursuit of communications entering or leaving America involving someone we believe is associated with al-Qaida.”

In an appearance that July before the Senate Judiciary Committee, Hayden again denied a mass data-collection effort. “So we do not vacuum up the contents of communications under the president’s program and then use some sort of magic after the intercept to determine which of those we want to listen to, deal with or report on.”

Bush’s attorney general, Alberto Gonzales, also minimized the reach of the NSA data-gathering, telling a Senate Judiciary hearing in February 2006 that “this surveillance is narrowly focused and fully consistent with the traditional forms of enemy surveillance found to be necessary in all previous armed conflicts.”

Bush administration officials were repeatedly pressed by Congress about the NSA efforts in 2005 and 2006, as the Senate and House debated whether to extend the Patriot Act and many of its provisions that gave the government broad power to conduct surveillance and data-collection. But once the Patriot Act’s main provisions were reauthorized and signed into law by Bush in March 2006, public congressional concerns over the NSA’s authority seemed to dissipate.

A review of congressional transcripts shows that from 2006 well into Obama’s first term, top administration officials were rarely questioned publicly about the NSA’s data-gathering activities. Instead, the agency’s new director, Keith B. Alexander, was most often pressed about the NSA’s growing efforts in cyberwarfare and security.

It was not until May 2011, as the Patriot Act again faced another reauthorization, that the NSA’s secret programs began to receive cryptic attention from two Democratic senators, Ron Wyden of Oregon and Mark Udall of New Mexico. Hobbled by the classified nature of the secret programs, the two senators offered up only guarded warnings.

“When the American people find out how their government has secretly interpreted the Patriot Act, they will be stunned and they will be angry,” Wyden said during a floor speech in May 2006. He added: “Many members of Congress have no idea how the law is being secretly interpreted by the executive branch, because that interpretation is classified.”

Still hamstrung by the programs’ security classification, Wyden pressed Director of National Intelligence James Clapper at a Senate Intelligence Committee hearing in March 2013 about the NSA. “Does the NSA collect any type of data at all on millions or hundreds of millions of Americans?” he asked.

“No, sir,” Clapper replied. He added: “Not wittingly. There are cases where they could inadvertently perhaps collect but not wittingly.”

This week, after the new revelations about the NSA’s massive data haul, Clapper acknowledged the existence of both of the agency’s secret operations and blasted the media disclosures as “reprehensible.”

When contacted by the National Journal about his earlier exchange with Wyden, Clapper stood by his earlier comments denying that the NSA is collecting massive troves of data.

“What I said was, the NSA does not voyeuristically pore through U.S. citizens’ e-mails,” Clapper said. “I stand by that.”