Google Inc. has agreed to pay $500 million to settle a U.S. government investigation into the Internet search leader's distribution of online ads from Canadian pharmacies illegally selling prescription and non-prescription drugs to American consumers, a U.S. attorney in Rhode Island said Wednesday.

The settlement means the Internet search leader will not face criminal prosecution for accusations that it improperly profited from ads promoting Canadian pharmacies that illegally imported drugs into the United States, U.S. Attorney Peter F. Neronha said.

The $500 million represents the gross revenues Google collected in ad buys from the Canadian pharmacies, plus the earnings generated from the illegal sales of drugs to American consumers, federal investigators said.

Federal officials also say Google knew as early as 2003 that its ad system was allowing Canadian pharmacies to make illegal sales. These transactions included the sale of prescription drugs without prescriptions from a licensed medical practitioner, federal prosecutors said.

Shipping prescription drugs into the U.S. from abroad violates drug and other laws, investigators said. Prescription drugs shipped into the U.S. from Canada are not subject to oversight by Canadian regulatory authorities and many sell drugs from countries with inadequate pharmacy regulations, prosecutors said.

The investigation laid bare how vulnerable the company's automated ad system known as AdWords is to the machinations of shady operators. The ad network is a major money maker for Google and is expected to generate more than $30 billion in revenue this year.

Google acknowledged holes in its ad system in a federal lawsuit filed last fall against dozens of "rogue" online pharmacies that were finding ways to place ads for drugs despite the company's efforts to prevent abuses. The individuals identified in the complaint were in New York, Tennessee and Ohio.

In one of the more common practices, the illicit drug dealers would plug subtle misspellings of drug names frequently entered into Google's search engine to generate ads alongside the results. For instance, one illegal drug advertiser spelled the anabolic steroid Dianabol as "Diano bol" in Google's automated system to produce an ad, according to the lawsuit in San Jose federal court.

Google has obtained court orders banning some of the rogue pharmacies named in the lawsuit and is still seeking injunctions against the others.

Rhode Island has aggressively investigated doping activities recently. Last year, the Chinese company GeneScience Pharmaceutical Co. and its CEO pleaded guilty to selling human growth hormone and agreed to pay $7.5 million.

The Google lawsuit came seven months after the Internet search leader imposed new restrictions on the kinds of pharmaceutical ads it would accept in the U.S. and Canada. The new rules were supposed to allows ads only from U.S. pharmacies that had been accredited by a special program run by the National Association Boards of Pharmacy. In Canada, the accreditation had to come from the Canadian International Pharmacy Association.

Google's critics have complained in the past that the company and other websites haven't been vigilant about policing pharmaceutical ads because they are so lucrative. Drug and health care advertising generated about $1 billion in Internet spending last year and is expected to grow to nearly $1.9 billion by 2015, according to the research firm eMarketer Inc.

The agreement also ends speculation that began in May when the company made a reference in its quarterly filing with the Securities and Exchange Commission to a Justice Department investigation into the usage of Google's automated system for placing ads alongside search results and other content at hundreds of thousands of websites. Google had raised even more intrigue by subtracting $500 million from its first-quarter earnings to cover a potential settlement.