WASHINGTON — The Justice Department is preparing to release hundreds of pages of secret court documents next week that could shed more light on a controversial National Security Agency program that gathers the phone records of tens of millions of Americans.

The documents, which include orders and opinions of the Foreign Intelligence Surveillance Court issued between 2004 and 2011, are being released under a Freedom of Information Act lawsuit filed by the Electronic Frontier Foundation (EFF), a civil liberties group.

The department said in a court filing that it would release the records by Tuesday.

The release will follow the disclosure last month of an 85-page surveillance court opinion that rebuked the NSA for violating Americans’ right to privacy as part of a separate program that targets the collection of foreigners’ e-mails and phone calls.

In that opinion, the judge scolded the agency for its collection of tens of thousands of “wholly domestic” e-mails in violation of the Constitution, and hinted that the NSA possibly violated a criminal law against spying on Americans.

A footnote in that opinion took the agency to task for violations related to the phone records collection. In that program, the agency maintains a storehouse of Americans’ call details, or metadata, including numbers called and received, time of calls and call duration. No content or subscriber names are collected.

“Contrary to the government’s repeated assurances, NSA had been routinely running queries of the metadata using querying terms that did not meet the required standard,” Judge John Bates wrote in the Oct. 3, 2011, opinion released last month, also in response to an EFF lawsuit.

In the spring of 2009, the Obama administration conducted a review of the NSA’s surveillance activities and found problems dating back years, including in the phone records program. It began what officials described as a robust compliance effort that included creating a new office at the agency and working with the court to remedy the problems.

“If there is as much released here as in the case concerning [the e-mail collection], we will have succeeded in putting a significant dent in the secret law that has governed a great deal of the NSA’s surveillance activity,” said David Sobel, EFF senior counsel.

The phone records collection began under the Bush administration shortly after the terrorist attacks of Sept. 11, 2001. In 2006, to reassure nervous phone companies, the government put the program under court oversight. The court authorized it under the “business records” provision of the Foreign Intelligence Surveillance Act.