By reaching a settlement, Google will avoid criminal prosecution in the US for profiting from the adverts.
The $500m represents the firm's revenues from the adverts and the revenues generated from the sale of the drugs, federal investigators said.
Google said it should it not have allowed the adverts.
"We banned the advertising of prescription drugs in the US by Canadian pharmacies some time ago," the company said in a short statement.
"However, it's obvious with hindsight that we should not have allowed these ads on Google in the first place."
The US Justice Department said controls over selling the drugs were inadequate.
"While Canada has its own regulatory rules for prescription drugs, Canadian pharmacies that ship prescription drugs to US residents are not subject to Canadian regulatory authority, and many sell drugs obtained from countries other than Canada which lack adequate pharmacy regulations," the department said.
It added that the higher price of the drugs reflected the fact that some could be bought without a doctor's prescription.
Internet giant Google has agreed to forfeit $500m (Â£306m) for publishing online adverts from Canadian pharmacies selling illegal drugs to US customers.