Reuters news agency says the firm built special software last year to comply with a classified request.
"Yahoo is a law abiding company, and complies with the laws of the United States," the tech firm said in a statement provided to the BBC.
The allegation comes less than a fortnight after Yahoo said hackers had stolen dataabout many of its users.