CVS Pharmacy Inc. agreed to pay $77.6 million to settle allegations that its drugstores sold large amounts of cough and cold medicines with the ingredient pseudoephedrine to criminal traffickers, who used it to make the highly addictive stimulant methamphetamine.

In an agreement negotiated with the U.S. Attorney’s Office in Los Angeles, the company — the nation’s largest pharmacy chain — admitted that it allowed illegal sales of the ingredient. The sales were mainly in California and Nevada, but the settlement also covers 23 other states where the government says CVS failed to put proper safeguards in place.

The settlement closes a federal investigation that began after CVS stores in Los Angeles County experienced a surge in 2007 of “smurfing,” in which individuals make multiple, small purchases of cough and cold medicines to collect pseudoephedrine for making meth.

The company’s electronic “Meth Tracker” monitoring system failed to detect the multiple purchases of pseudoephedrine made by customers on the same day. According to a news release from the U.S. Attorney’s Office, that violated the Combat Methamphetamine Epidemic Act of 2005, which also requires retailers to keep products with pseudoephedrine behind the counter and to require customers to give their signature when they make a purchase.

“CVS knew it had a duty to prevent methamphetamine trafficking, but it failed to take steps to control the sale of a regulated drug used by methamphetamine cooks as an essential ingredient for their poisonous stew,” said U.S. Attorney André Birotte Jr. CVS changed its sales practices to prevent the illegal sales after it became aware of the government’s investigation.

The company will pay $75 million in civil penalties, the largest civil fine ever paid under the 40-year-old Controlled Substances Act, of which the methamphetamine act is a part. It also agreed to forfeit $2.6 million in profits that resulted from the illegal sales and to implement a compliance and ethics program.

In a statement, Thomas M. Ryan, chairman and chief executive of CVS Caremark, the chain’s parent company, said the illegal sales reflected “an  unacceptable breach of the company’s policies and was totally inconsistent with our values.” He said the company has taken steps to improve handling and monitoring of pseudoephedrine “to make certain this kind of lapse never takes place again.”

Over a 10-month period in 2008, sales of products containing pseudoephedrine more than doubled in Los Angeles County compared to the same period in 2007, according to the Associated Press. Meth is imported illegally into the U.S. but also commonly is made at home by sellers, and it often is linked to violence and other crimes.