The Google logo is seen at the Google headquarters in Mountain View, California on September 2, 2011

Google has agreed in a court settlement to spend at least $250 million over the next five years to help fight illegal online pharmacies selling to US customers, documents showed Friday.

The US Internet search giant made the commitment in settling a lawsuit from shareholders alleging Google failed to take adequate measures to prevent foreign from using its .

The lawsuit was filed in 2011 after Google paid a $500 million settlement to the US government over charges it sold advertisements to Canada-based online pharmacies which marketed drugs to Americans in violation of US law.

In a settlement filed in federal court in California, Google agreed to spend at least $50 million per year in each of the coming five years on "product quality operations, policy enforcement, and user safety initiative" to prevent the ads from appearing.

Google said its audit committee would set up a plan "to ensure compliance with federal and state laws and regulations" and to prevent the advertising of pharmaceuticals and supplements which violate the law running through its AdWords platform.

In the settlement with the US government, authorities said the online pharmacies from Canada used Google's Adwords programs, which deliver ads based on a user's browsing history and search queries, from 2003 to 2009.