Google Inc. has agreed to pay $500 million to settle a federal investigation into the Internet search leader's distribution of online ads from Canadian pharmacies that were illegally selling prescription and non-prescription drugs to American consumers.

The search giant will forefeit that amount for allowing Canadian drug sellers to use the company's AdWords service to market to U.S. buyers. The sale of prescription drugs across the U.S. border is often covered under the Controlled Substances Act, and Google was aware of that fact since as far back as 2003, a release from the U.S. Department of Justice says.

"The Department of Justice will continue to hold accountable companies who in their bid for profits violate federal law and put at risk the health and safety of American consumers," Deputy Attorney General James M. Cole said.

"This settlement ensures that Google will reform its improper advertising practices with regard to these pharmacies while paying one of the largest financial forfeiture penalties in history."

The department says Google provided customer support to some of these Canadian online pharmacy advertisers to assist them in placing and optimizing their AdWords advertisements, and in improving the effectiveness of their websites.

The settlement means Google will not face criminal prosecution for accusations it improperly profited from ads promoting Canadian pharmacies that illegally imported drugs into the United States.

"We banned the advertising of prescription drugs in the U.S. by Canadian pharmacies some time ago," a statement from the company said. "However, it's obvious with hindsight that we shouldn't have allowed these ads on Google in the first place." The company declined further comment. Google shares up slightly, trading at about $519.

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.

Rhode Island has aggressively pursued doping investigations in recent years.

The investigation against Google began after a separate multimillion-dollar financial fraud, the main target of which fled to Mexico. While a fugitive, he began to advertise illegal drug sales through Google's AdWords program.

After being apprehended in Mexico and returned to the United States, he co-operated with law enforcement and provided officials with precise details of how to get around the system.

With files from The Associated Press