WASHINGTON — Attorney General Eric Holder on Tuesday defended the Justice Department’s secret examination of Associated Press phone records though he declared he had played no role in it, saying it was justified as part of an investigation into a grave national security leak.

The government’s wide-ranging information gathering from the news cooperative has created a bipartisan political headache for President Barack Obama, with prominent Republicans and Democrats on Capitol Hill expressing outrage, along with press freedom groups.

The government obtained the records from April and May of 2012 for more than 20 separate telephone lines assigned to AP and its journalists, including main offices. AP’s top executive called the action a massive and unprecedented intrusion into how news organizations do their work.

Federal officials have said investigators are trying to hunt down the sources of information for a May 7, 2012, AP story that disclosed details of a CIA operation in Yemen to stop an airliner bomb plot around the anniversary of the killing of Osama bin Laden. The probe is being run out of the U.S. Attorney’s office in the District of Columbia.

Asked about it at a news conference on a separate topic, Holder said he removed himself from the leaked-information probe because he himself had been interviewed by FBI agents as part of the investigation. He said he wanted to ensure that the probe was independently run and to avoid any appearance of a conflict of interest. It was the Justice Department’s No. 2 official, Deputy Attorney General James Cole, who made the decision to seek news media phone records, the department said.

“This was a very serious leak, a very grave leak” that “put the American people at risk,” Holder said. He called it one of the two or three most serious such episodes he had seen since he became a prosecutor in 1976 but did not say specifically how the disclosure of information about the plot had endangered Americans.

In a letter to AP on Tuesday, Cole said the Justice Department had adhered to its rules for subpoenas for the news media and hadn’t sought information about the content of calls. “The records have not been and will not be provided for use in any other investigations,” Cole wrote.