The judge in Los Angeles said Starbucks and about 90 other coffee sellers had failed to warn customers about a potentially toxic compound that is produced during the roasting process.
The firms were sued by a California-based non profit-group over the chemical acrylamide.
The group argued that as acrylamide is regarded as carcinogenic under state law, it should be sold with a warning.
Ruling in favour of the Council for Education and Research on Toxics, Superior Court Judge Elihu Berle said the companies should not be exempt from the law, as they had failed to prove that the “consumption of coffee confers a benefit to human health”.
The companies have until 10 April to appeal the decision.
Acrylamide is created when starchy foods are roasted, grilled or fried for long periods at high temperatures.
Studies in animals found that the chemical causes tumours. This suggests that it also has the potential to cause cancer in humans.
Scientists believe that there should be a margin of exposure of 10,000 or higher between an average adult’s intake of acrylamide and the lowest dose which could cause adverse effects.
But at the moment the numbers are 425 for the average adult and 50 for the highest consuming toddlers, making it a slight public health concern, UK and European food safety experts say.
A statement from the National Coffee Association (NCA) said the industry was considering an appeal.
“Cancer warning labels on coffee would be misleading. The US government’s own Dietary Guidelines state that coffee can be part of a healthy lifestyle,” the statement said.
The lawsuit was filed in 2010 and says coffee sellers should pay fines of up to $2,500 (£1,800) for every person exposed to acrylamide in California since 2002.
The next phase of the trial will determine the exact penalties, but some companies have reportedly agreed to settle and post warnings about the chemical.
The ruling came despite a recent easing of concern about the potential health impact of coffee, which was removed from a list of possible carcinogens by the UN’s World Heath Organization in 2016.
Last year, a study of almost half a million people from 10 European countries found that drinking three cups of coffee a day may have health benefits.
But sceptical experts said it was impossible to say for sure that the coffee was having a protective effect.