UK spies had acted illegally when they collected data on British residents' online communications that was gathered by the US National Security Agency, a British court has ruled in a landmark judgment against Britain's security services.
But the judges said in the verdict on Friday that now, since details of the practices were known, they were within the law.
Britain's Investigatory Powers Tribunal, which deals with complaints against the intelligence services, ruled in a case brought by civil liberties groups against the electronic intelligence agency, GCHQ.
It said that before December 2014, "the regime governing the soliciting, receiving, storing and transmitting by UK authorities of private communications of individuals" gathered by the NSA contravened European Union protections of privacy and freedom of expression.
But it said the practices were now legal - because the rights groups' lawsuit had made details of the practices and the safeguards on them public.
The groups brought the case after former US intelligence analyst Edward Snowden's disclosures about the mass harvesting of communications data.
Snowden disclosed NSA programmes known as PRISM - which accessed data from Internet firms such as Yahoo and Google - and Upstream, which tapped into undersea communications cables.
The groups that brought the claim - Liberty, Privacy International, Bytes for All and Amnesty International - called the judgment a partial victory. It is the first time the tribunal has ruled against an intelligence agency since it was established 15 years ago.
Eric King, Privacy International's director, said the ruling confirmed "what many have said all along - over the past decade, GCHQ and the NSA have been engaged in an illegal mass surveillance-sharing programme that has affected millions of people around the world."
The groups said they would appeal the ruling that the data-sharing was now legal to the European Court of Human Rights.
GCHQ said it was pleased the court had found that it complied with the law. It also said the ruling "does not require GCHQ to change what it does to protect national security in any way."