The Justice Department released two decade-old memos Friday night, offering the fullest public airing to date of the Bush administration’s legal justification for the warrantless wiretapping of Americans’ phone calls and e-mails — a program that began in secret after the 2001 terrorist attacks.

The broad outlines of the argument — that the president has inherent constitutional power to monitor Americans’ communications without a warrant in a time of war — were known, but the sweep of the reasoning becomes even clearer in the memos written by then-Assistant Attorney General Jack Goldsmith, who was head of President George W. Bush’s Office of Legal Counsel.

“We conclude only that when the nation has been thrust into an armed conflict by a foreign attack on the United States and the president determines in his role as commander in chief . . . that it is essential for defense against a further foreign attack to use the [wiretapping] capabilities of the [National Security Agency] within the United States, he has inherent constitutional authority” to order warrantless wiretapping — “an authority that Congress cannot curtail,” Goldsmith wrote in a redacted 108-page memo dated May 6, 2004.

The program, code-named Stellar Wind, enabled the NSA to collect communications on U.S. soil when at least one party was believed to be a member of al-Qaeda or an al-Qaeda affiliate, and at least one end of the communication was overseas.

Its existence was revealed in 2005 by the New York Times, setting off great controversy, and the program was finally brought under court oversight in 2007.

“What these memos show is that nearly three years after President Bush authorized the warrantless wiretapping of Americans’ e-mails and phone calls, government lawyers were still struggling to put the program on sound legal footing,” said Patrick Toomey, staff attorney for the American Civil Liberties Union, which obtained the memos through a Freedom of Information Act lawsuit.

The memos were also obtained by the Electronic Privacy Information Center.

“Their conclusions are deeply disturbing,” he said. “They suggest that the president’s power to monitor the communications of Americans is virtually unlimited — by the Constitution, or by Congress — when it comes to foreign intelligence.”

Goldsmith argued that Congress’s 2001 Authorization for the Use of Military Force passed shortly after the al-Qaeda attacks on the United States provided “express authority” for the warrantless program. “In authorizing ‘all necessary and appropriate force,’ ” he reasoned, the AUMF necessarily applied to electronic surveillance, including domestically.

He also asserted that the authorization can be read to “provide specific authority . . . that overrides the limitations” of the Foreign Intelligence Surveillance Act, a law passed in 1978 that required a court order to wiretap an American or any person on U.S. soil.

So broad is the president’s Article II power, that he can conduct warrantless searches for foreign intelligence purposes without congressional approval “even in peacetime,” Goldsmith stated, citing Supreme Court cases and the Federalist papers.

In a second memo, dated July 16, 2004 , Goldsmith argued that a Supreme Court decision reached weeks earlier, involving a U.S. citizen named Yaser Esam Hamdi captured on the battlefield in Afghanistan, bolstered the reasoning of his first memo. Five justices in the decision, he said, agreed that Hamdi’s detention was authorized because it is a “fundamental” and “accepted” incident of waging war, he said.

“Because the interception of enemy communications for intelligence purposes is also a fundamental and long-accepted incident of war, the [AUMF] likewise provides authority for Stellar Wind,” he said.

The Hamdi decision, Toomey noted, did not make any mention of wiretapping or intelligence collection on U.S. soil.

The memos were written at a time of high-level internal debate about the legality of the surveillance programs. And the unredacted portions do not reveal much analysis about what was reported to have been at the time the most controversial of the programs: the NSA’s bulk collection of e-mail metadata, or mass gathering of information such as the to-from lines in an e-mail.

In March 2004, the OLC concluded the e-mail program was not legal, and then-Acting Attorney General James Comey refused to reauthorize it.

That refusal resulted in a dramatic showdown that month between Attorney General John Ashcroft, who was in the hospital with a severe pancreatic ailment, and White House counsel Alberto Gonzales, who had rushed to Ashcroft’s hospital bedside in a futile attempt to persuade him to reauthorize the e-mail program. In July 2004, the Foreign Intelligence Surveillance Court authorized the program under a theory that bulk e-mail collection could be relevant to a terrorism investigation. That program was shut down in 2011.

“Unfortunately, the sweeping surveillance they sought to justify is not a thing of the past,” Toomey said. “The government’s legal rationales have shifted over time, but some of today’s surveillance programs are even broader and more intrusive than those put in place more than a decade ago by President Bush.”

The warrantless program was placed under statute in 2007 and 2008 by Congress. The current program, known as Section 702 of the FISA Amendments Act, gives the government authority to collect communications on U.S. soil when the target is believed to be a foreigner overseas — not just for purposes of countering terrorism, but also for broader foreign intelligence purposes.