The tech company allegedly searched hundreds of millions of email accounts for a specific phrase to help a US intelligence agency.
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.
Executives were riled when Yahoo president Marissa Mayer complied