SAN FRANCISCO — Google agreed on Monday to pay $17 million to 37 states and the District of Columbia in a wide-reaching settlement over tracking consumers online without their knowledge.

The case involved Google’s bypassing of privacy settings in Apple’s Safari browser to use cookies to track users and show them advertisements in 2011 and 2012. Google has said it discontinued circumventing the settings early last year, after the practice was publicly reported, and stopped tracking Safari users and showing them personalized ads.

The fine is a tiny fraction of the billions of dollars that Google earns in advertising revenue each year. But the case is one of a growing pile of government investigations, lawsuits and punishments related to privacy matters at the company. They include cases involving a social networking tool called Buzz, illegal data collection by Street View vehicles and accusations of wiretapping to show personalized ads in Gmail.

“Consumers should be able to know whether there are other eyes surfing the web with them,” Eric T. Schneiderman, attorney general of New York, said in a statement. “By tracking millions of people without their knowledge, Google violated not only their privacy, but also their trust.”