British spy agency GCHQ intercepted webcam images from millions of Yahoo users around the world, according to a report in the Guardian.
Yahoo denied prior knowledge of the alleged programme, describing it as a "completely unacceptable" privacy violation.
According to leaked documents, sexually explicit images were among those gathered - although not intentionally.
In a statement GCHQ has said all of its actions are in accordance with the law.
The operation, which was called Optic Nerve and was aided by the US National Security Agency, is alleged to have stored images between 2008 and 2010. In one six-month period in 2008, images from 1.8m users were gathered.
The report originated from documents leaked by whistleblower Edward Snowden.
It suggested that sexually explicit content would be captured by the system.
"Unfortunately … it would appear that a surprising number of people use webcam conversations to show intimate parts of their body to the other person," it read.
"Also, the fact that the Yahoo software allows more than one person to view a webcam stream without necessarily sending a reciprocal stream means that it appears sometimes to be used for broadcasting pornography."
'Whole new level'
"We were not aware of nor would we condone this reported activity," Yahoo said in an emailed statement.
"This report, if true, represents a whole new level of violation of our users' privacy that is completely unacceptable and we strongly call on the world's governments to reform surveillance law consistent with the principles we outlined in December.
"We are committed to preserving our users' trust and security and continue our efforts to expand encryption across all of our services."
A statement from GCHQ said it would not comment on matters of intelligence, but added: "All of GCHQ's work is carried out in accordance with a strict legal and policy framework which ensures that our activities are authorised, necessary and proportionate, and that there is rigorous oversight, including from the secretary of state, the interception and intelligence services commissioners and the Parliamentary Intelligence and Security Committee.
"All our operational processes rigorously support this position."