WASHINGTON — President George W. Bush sought to retroactively authorize portions of the National Security Agency’s post-9/11 surveillance and data collection program after a now-famous incident in 2004 in which his attorney general refused to certify the program as lawful from his hospital bed, according to newly declassified portions of a government investigation.

Mr. Bush’s effort to salvage the surveillance program without changes did not satisfy top Justice Department officials, who threatened to resign. But the newly disclosed passages of a report by inspectors general of six agencies suggest that the confrontation in the hospital room came after the Justice Department identified several problems, including a “gap” between what Mr. Bush had authorized the N.S.A. to collect and what the agency was collecting in practice.

A leak of government documents in 2013 revealed that the fight had been partly about the legality of the N.S.A.’s collection of data about Americans’ emails in bulk. But the latest disclosure shows that the Justice Department had additional concerns.

For example, Mr. Bush’s secret directives to the agency, starting in October 2001, said the N.S.A. could “acquire” phone and email metadata — logs showing who contacted whom, but not what they said — if at least one end was foreign or if a specific message were linked to terrorism. But the agency was apparently gathering purely domestic metadata in bulk, too, the Justice Department found.

Mr. Bush, in response to the discrepancy identified by the Justice Department, declared that the N.S.A. was authorized to systematically collect the metadata of purely domestic communications, too, so long as analysts only looked at records linked to terrorism. He also declared that the agency had been authorized to do that all along.

The authorization “gap” was among the disclosures in newly declassified passages of a 746-page report by six agencies’ inspectors general about the N.S.A. program, code-named Stellarwind. The report also shows that after March 2004, the Justice Department persuaded the White House to limit the program to investigations of Al Qaeda, rather than allowing it to be used for other types of international counterterrorism investigations, to make the argument that the program was legally justified as a wartime measure.

The government provided the information to The New York Times late Friday night as part of a Freedom of Information Act lawsuit seeking the public disclosure of the report.

Stellarwind, which started after the terror attacks of Sept. 11, 2001, involved warrantless wiretapping of terrorism suspects’ international phone calls and emails, as well as the bulk collection of metadata about Americans’ emails and phone calls. It bypassed rules established by the Foreign Intelligence Surveillance Act, such as a requirement to obtain court permission for wiretaps.

Justice Department officials — Attorney General John Ashcroft and John Yoo, then a lawyer in the Office of Legal Counsel — initially said the program was lawful. Mr. Yoo subscribed to a sweeping version of a theory that the president, as commander in chief, can lawfully override statutes restricting what he can do in a national-security matter.

By 2004, turnover in the department had brought new officials to power, including Jack Goldsmith, a new head of its Office of Legal Counsel, and James Comey, a deputy attorney general who temporarily became the acting head of the department that March when Mr. Ashcroft was hospitalized. (Mr. Comey is now director of the Federal Bureau of Investigation.)

Image

President Bush in 2003 with Attorney General John Ashcroft, who refused to authorize a data-collection program as lawful.CreditDoug Mills/The New York Times

Taking a second look at the legal basis for various post-9/11 programs, Mr. Goldsmith and an aide, Patrick Philbin, uncovered problems with Stellarwind. Mr. Goldsmith thought Mr. Yoo’s legal theory was too sweeping, and he spotted disparities between the basis for the program on paper — how Mr. Yoo’s memos and Mr. Bush’s authorizations described it — and what the government was doing.

While the public has long known about the March 2004 hospital room fight that resulted from their skepticism, the details of the dispute have remained murky. Two years ago, leaked documents revealed one piece of the dispute: whether a component of Stellarwind that collected bulk data about Americans’ emails was legal.

The newly revealed passages in the report show that the fight was about more than that. The passages consist largely of quotations and descriptions of the evolving Stellarwind authorization orders that Mr. Bush periodically signed, and which were drafted by David Addington, the top counsel to Vice President Dick Cheney.

Although some lines in the report remain redacted, it appears that another problem centered on the N.S.A.’s acquisition of bulk domestic metadata. It used phone numbers and email addresses linked to terrorism to search that data, hunting for hidden associates of terrorism suspects.

But the text of Mr. Bush’s authorizations to the N.S.A. directed it “acquire” phone and email metadata only if at least one end of the communications were of foreigners abroad, or if the specific call or email was linked to terrorism. The bulk collection of purely domestic metadata would seem to go beyond the scope of that authority, even if Mr. Yoo’s theory of presidential power was accurate, because Mr. Bush had not explicitly authorized the collection of such data.

This gap was one of several concerns that prompted the Justice Department, led temporarily by Mr. Comey because Mr. Ashcroft was sick, to refuse to recertify that the program was lawful as it was operating at the time. On March 10, 2004, White House officials visited the hospital room of Mr. Ashcroft and asked him to overrule Mr. Comey. Mr. Ashcroft refused, citing Mr. Goldsmith’s analysis.

The next day, Mr. Bush reauthorized the program anyway without Justice Department approval. This time, Mr. Addington drafted additional language as a “fix,” the report said.

Among them, “to narrow the gap between the authority given on the face of prior authorizations and the actual operation of the program by the N.S.A.,” the report said, Mr. Bush’s new authorization proclaimed that the N.S.A. could “obtain and retain” metadata in general, and that the agency would be deemed to have “acquired” only those records that analysts specifically “searched for and retrieved” within the larger database.

This formulation appeared to permit bulk collection of domestic metadata, so long as the N.S.A. searched the database only for records related to terrorism suspects.

Mr. Bush also declared that this newly drafted distinction between obtaining and acquiring data reflected previous N.S.A. conduct that had been “known to and authorized by me.” The new language, Mr. Bush added, would be deemed to have been a part of his previous authorizations as if those words had been included in them when he signed them, so that he was ratifying and confirming the N.S.A.’s prior actions.

Mr. Addington also added language in which Mr. Bush, for the first time, explicitly said that his authorizations were “displacing” specific federal statutes, including the Foreign Intelligence Surveillance Act and criminal wiretapping laws. The White House counsel, Alberto Gonzales, then told Mr. Goldsmith that the president had “made an interpretation of law concerning his authorities” and that the Justice Department could not act in contradiction of Mr. Bush’s determinations.

But Mr. Bush’s willingness to go forward with the program without operational changes prompted a threat of mass resignation by top department officials. To avert that meltdown, Mr. Bush then agreed to accept curbs on the program.

A version of this article appears in print on , on Page A13 of the New York edition with the headline: Bush Made Retroactive N.S.A. ‘Fix’ After Hospital Room Showdown. Order Reprints | Today’s Paper | Subscribe