Wells Fargo has agreed to pay $3 billion and admit wrongdoing to settle criminal and civil investigations with the Justice Department and the Securities and Exchange Commission over its fraudulent fake-account scandal, the U.S. Attorney's Office said Friday.

"This case illustrates a complete failure of leadership at multiple levels within the bank," said U.S. Attorney Nick Hanna. "Simply put, Wells Fargo traded its hard-earned reputation for short-term profits, and harmed untold numbers of customers along the way."

San Francisco-based Wells Fargo avoids criminal prosecution as part of the deal. It struck a three-year deferred prosecution agreement to resolve a criminal investigation into false bank records and identity theft. It must abide with terms of the agreement, to avoid prosecution, including continuing to cooperate with ongoing investigations.

As part of the agreements, the nation's fourth-largest bank admitted it collected millions of dollars in fees and interest that it should not have collected, harmed the credit ratings of customers, and unlawfully misused customers' sensitive personal information.

Wells Fargo's $3 billion payment includes a $500 million civil penalty to be distributed by the SEC to investors.

By contrast, Wells Fargo reported a net profit of $19.5 billion in 2019.

The settlement represents the latest government penalties for Wells Fargo and its former management for malfeasance in which millions of fake accounts were set up to meet sales quotas. They included checking and savings accounts, credit and debit cards and bill pay services. These practices went on for over a decade, Hanna said, and involved thousands of employees trying to meet unrealistic sales quotas.

Last month, the Office of the Comptroller of the Currency said that former Wells Fargo CEO John Stumpf, who managed the company during the peak of the scandal, has been barred from working at a bank again and that he will pay $17.5 million for his role.

Wells Fargo has remained entrenched in regulatory oversight since 2016 after revelations of fraud at its consumer-facing community bank. Wells came under intense scrutiny at the time, when the Consumer Finance Protection Bureau and other government bodies fined the company for fabricating millions of phony accounts to meet sales quotas.

"We are hopeful that this $3 billion penalty, along with the personnel and structural changes at the bank, will ensure that such conduct will not reoccur," Hanna said.

Subscribe to CNBC PRO for exclusive insights and analysis, and live business day programming from around the world.