This June 6, 213 file photo shows the sign outside the US National Security Agency (NSA) campus in Fort Meade, Md. AP

WASHINGTON – The US government spied on electronic communications between Americans with no links to terror suspects until a judge ruled it illegal in 2011, officials acknowledged Wednesday.

The unlawful program, which involved tens of thousands of emails, was revealed in declassified documents from the Foreign Intelligence Surveillance Court, which reviews the legality of eavesdropping programs.

The court’s opinions are usually kept secret but the government chose to release the documents amid a firestorm over sweeping surveillance operations, following bombshell leaks from a former US intelligence contractor, Edward Snowden.

Officials said the court rulings had been declassified to better inform the public about how the eavesdropping programs are carried out with what they called rigorous “oversight.”

Under the program, addressed by the court in 2011, the NSA had diverted a massive trove of international data flowing through fiber-optic cables in the United States, purportedly to sift through foreign communications.

But the NSA proved unable to separate out emails between Americans who had no links to terror suspects, and the agency was collecting tens of thousands of “wholly domestic communications” every year, the court said in documents posted by the Office of the Director of National Intelligence.

The court concluded the program violated privacy rights enshrined in the Fourth Amendment to the US Constitution.

The surveillance resulted “in the acquisition of a very large number of Fourth Amendment-protected communications that have no direct connection to any targeted facility and thus do not serve the national security needs” defined under the law, the court said.

The government altered the program and later came back to the court for approval of a revised surveillance operation.

A senior US official, who spoke to reporters on condition of anonymity, played down the surveillance violation as “a technological problem” rather than an intentional invasion of privacy.”

“These documents released today will provide a strong indication to back up the statements we’ve been making from the beginning about the strong nature of the oversight of this program,” said the official.

“This is not an egregious overreaching,” he said, adding it was merely “an inadvertent problem that involved a relatively small number of US persons.”

But the court, in its ruling, disagreed with the government’s claim the collection was inadvertent and demanded the NSA change the program.

Citing the declassified documents, rights advocates expressed alarm at the scale of the surveillance and said the government had to do more to reassure the public.

“The FISA court opinion released today serves as further confirmation that the NSA is tapping the domestic Internet backbone,” the Center for Democracy and Technology, a think tank, said in a tweet.

Democratic Senator Mark Udall – a long-time critic of the surveillance programs –welcomed the NSA’s decision to reveal the details of the episode but said more protections were needed to safeguard civil liberties.

“I am glad the NSA is taking this step at owning its mistakes, but it is also a sign that we can and must do more to protect innocent Americans with no connection to terrorism from being monitored by our government – whether intentionally or not,” Udall said.

The government’s biggest challenge was to restore the public’s trust, said Sascha Meinrath, director of the Open Technology Institute.

“It’s time for the Obama administration to come clean about the full scope of its activities,” Meinrath said in a statement.

President Barack Obama has insisted that Americans’ privacy rights are protected and that surveillance powers have not been abused in the search to uncover terror plots.

The scope of America’s massive electronic spying effort – which sweeps up Internet traffic and phone records – was exposed starting in June when news outlets reported on documents leaked to them by Snowden.

The 30-year-old Snowden is wanted by the United States on espionage charges over his leaks but has obtained temporary asylum in Russia.

Complete stories on our Digital Edition newsstand for tablets, netbooks and mobile phones; 14-issue free trial. About to step out? Get breaking alerts on your mobile.phone. Text ON INQ BREAKING to 4467, for Globe, Smart and Sun subscribers in the Philippines.

Disclaimer: The comments uploaded on this site do not necessarily represent or reflect the views of management and owner of INQUIRER.net. We reserve the right to exclude comments that we deem to be inconsistent with our editorial standards.