Yahoo secretly created a custom piece of software which searched its customers' emails for specific information requested by US intelligence officials, Reuters reports.
Former employees at the tech company claim hundreds of millions of Yahoo Mail accounts were being scanned following a request from either the National Security Agency or FBI.
All arriving messages from other email addresses were affected, and it is not known what phrases were being searched for.
Yahoo's decision to comply with the request is said to have infuriated some of the company's top executives - especially as the tech giant's security team was not involved in building the secretive program which scoured messages.
When the security team discovered the software, they thought it had been created by hackers, and reportedly found a programming flaw which meant a hacker could have accessed the emails flagged up as including the phrase intelligence officials had specified.
It is not clear whether Yahoo handed over any of the data obtained through the searches, which began last year, to intelligence agencies.
In a statement, the company said: "Yahoo is a law-abiding company, and complies with the laws of the United States."
Security experts say it is likely that the intelligence agency behind the request also made similar demands to other email providers.
In a statement, Google said: "We've never received such a request, but if we did, our response would be simple: 'No way'."
A Microsoft spokesperson did not comment on whether it had received a request, but added: "We have never engaged in the secret scanning of email traffic like what has been reported today about Yahoo."
Albert Gidari of Stanford University said it would have been "really difficult" for Yahoo to create computer software which searched many millions of messages for a specific phrase in real time - and claimed such a request from intelligence agencies was unprecedented.
It is legal for intelligence agencies to ask internet companies to provide customer data for many reasons, including the prevention of terror attacks.
Companies can challenge an agency's request in court - and earlier this year, Apple refused an FBI demand to break into a locked iPhone which was used by one of the attackers in the San Bernardino shootings.
Patrick Toomey of the American Civil Liberties Union said it was "deeply disappointing" that Yahoo declined to challenge the order, adding: "Customers are counting on technology companies to stand up to novel spying demands in court."
Last month, Yahoo revealed that the details of 500 million users had been stolen by what it described as a "state-sponsored actor", with eight million Britons among those affected.
There was speculation that the fallout from the hack could have implications for Verizon's $4.8bn (£3.7bn) purchase of Yahoo - and Verizon is yet to respond to these latest claims.
(Sky News)