Bank of America agreed Wednesday to pay nearly $800 million in penalties for deceiving millions of customers into buying costly and unneeded services when they signed up for credit cards.

Americans gravitated to credit protection products that promised debt cancellation or deferment to shield themselves from unforeseen economic problems in the wake of the recession. But in an aggressive push to sell these credit card add-ons, some financial firms glossed over the terms or enrolled unwitting customers.

Examiners at the Consumer Financial Protection Bureau say that is what Bank of America and its telemarketers did for several years.

The bank will pay $268 million to reimburse about 1.4 million consumers who paid for credit protection services that they never fully received between 2010 to 2012 . Another $459 million will go to 1.5 million customers who were hit with unauthorized charges for identity protection products from October 2000 through September 2011, according to the CFPB.

The watchdog agency also slapped Bank of America with a $20 million civil penalty, which will go to the bureau’s fund for victim relief and financial literacy. The CFPB also is barring the bank from marketing any credit monitoring or protection products until it submits a plan for improving its program.

In coordination with the CFPB, the Office of the Comptroller of the Currency levied a separate $25 million penalty against Bank of America. The OCC also is requiring the bank to take a number of corrective measures, including developing a better risk-management program for consumer products marketed or sold by Bank of America or its vendors.

Wednesday’s order against Bank of America marks the fifth action the CFPB has taken against financial firms peddling credit card add-ons. Previous cases, which have returned $1.5 billion to consumers, involved JPMorgan Chase and Capital One.

“We have seen several cases of deceptive marketing and illegal billing in this market. Here, Bank of America was doing both,” Richard Cordray, director of the CFPB, said during a call with reporters Wednesday.

Cordray said Bank of America misled customers into believing the bank was just sending them additional information about credit protection products when in actuality they were being enrolled in the program. In the two years the payment protection products were on the market, they generated hundreds of millions of dollars in revenue for the company, he said.

What’s more, the CFPB said, Bank of America often charged consumers for identity protection products before the bank had obtained written authorization to perform the service, a violation of the law. In some cases, the bank never received authorization but started billing customers for the service anyway.

“Instead of consumers receiving the protection they were promised, they were being illegally charged by one of the nation’s largest banks for little or no benefit to themselves,” Cordray said.

Bank of America says it has already made refunds to a majority of affected consumers. Customers who are still with the bank will receive credits to their accounts, if they have not already. Those who are no longer with Bank of America have received or will be mailed checks.

“Bank of America stopped marketing identity theft protection products in December 2011 and credit card debt cancellation products in August 2012,” company spokesman Tony Allen said. He said the bank brought the problems to regulators’ attention nearly two years ago. Since then, Bank of America has been locked in negotiations with the OCC and the CFPB to resolve the matter.