WASHINGTON – The National Security Agency declassified three secret U.S. court opinions Wednesday showing how it scooped up as many as 56,000 emails and other communications by Americans with no connection to terrorism annually over three years, and how it revealed the error to the court and changed how it gathered Internet communications.

Director of National Intelligence James Clapper authorized the release Wednesday.

The NSA reported the problems in how it was gathering Internet communications to the court and shortly thereafter to Congress in the fall of 2011. The opinions show that at that time, the court ordered the NSA to find ways to limit what it collects and how long it keeps it.

While the NSA is allowed to keep the metadata — the address or phone number and the duration, but not the content, of the communication — of Americans for up to five years, the court ruled that when it gathered up such large packets of information that included actual emails between U.S. citizens, it violated the Constitution’s ban against unauthorized search and seizure.

In the opinion by the Foreign Intelligence Surveillance Court denouncing the practice, the judge wrote that the NSA had advised the court that “the volume and nature of the information it had been collecting is fundamentally different than what the court had been led to believe,” and went on to say that the court must consider “whether targeting and minimization procedures comport with the 4th Amendment.”

Under court order, the NSA resolved the problem by creating new ways to detect when emails by people within the U.S. were being intercepted, and separated those batches of communications.

It also developed new ways to limit how that data could be accessed or used.

The agency also agreed to only keep these bundled communications for a 2-year period, instead of the usual 5-year retention period.