New York (CNN Business) Wells Fargo was hit with a $3 billion fine Friday by federal authorities outraged by the millions of fake accounts created at the troubled bank over many years.

The settlement with the Justice Department and Securities and Exchange Commission, years in the making, resolves Wells Fargo's criminal and civil liabilities for the fake-accounts scandal that erupted nearly four years ago.

The deal does not, however, remove the threat of prosecution against current and former Wells Fargo employees.

Prosecutors slammed Wells Fargo for the "staggering size, scope and duration" of the unlawful conduct uncovered at one of America's largest and most powerful banks.

As part of the deal, Wells Fargo admitted that between 2002 and 2016, it falsified bank records, harmed the credit ratings of customers, unlawfully misused their personal information and wrongfully collected millions of dollars in fees and interest.

"Today's announcement should serve as a stark reminder that no institution is too big, too powerful, or too well-known to be held accountable and face enforcement action for its wrongdoings," US Attorney Andrew Murray for the Western District of North Carolina said in a statement.

The settlement focused squarely on Wells Fargo's fake-accounts scandal, not the mistreatment of workers , auto borrowers homebuyers and other customers that the bank has been accused of in recent years.

Authorities said Friday that the criminal investigation into false bank records and identify theft at Wells Fargo is being resolved by what's known as a deferred prosecution agreement. Under that agreement, authorities have agreed not to prosecute Wells Fargo for three years as long as it abides by certain conditions, including its continued cooperation with "further" government investigations.

In a statement, Wells Fargo CEO Charlie Scharf, who joined the company in September, said, "the conduct at the core of today's settlements — and the past culture that gave rise to it — are reprehensible and wholly inconsistent with the values on which Wells Fargo was built. Our customers, shareholders and employees deserved more from the leadership of this company."

Wells Fargo has also reached a civil settlement over its creation of false bank records with the SEC over its conduct. The $3 billion fine resolves all three investigations.

'Remarkable' fraudulent conduct

The SEC and Justice Department's settlement still leaves open the possibility that current and former Wells Fargo employees could be prosecuted. And in the agreement Wells Fargo admits that senior executives were aware of the illegal activity long ago.

"The top managers of the community bank were aware of the unlawful and unethical gaming practices as early as 2002," the settlement said.

Yet Wells Fargo executives repeatedly refused to acknowledge the shady behavior was being driven by the bank's wildly unrealistic sales goals, which were at the heart of the company's business model. Authorities said that senior executives at the community bank "minimized the problems" by shifting the blame to "individual misconduct instead of the sales model itself."

"This settlement holds Wells Fargo accountable for tolerating fraudulent conduct that is remarkable both for its duration and scope, and for its blatant disregard of customers' private information," Michael Granston, deputy assistant attorney general at the Department of Justice's civil division, said in the statement.

Not out of the penalty box yet

Visa V Bank of New York Mellon BK The agreement removes a major cloud that has been hovering above Wells Fargo for years and shows the emphasis by the bank's new management to move past the scandals. Scharf, the well-respected former CEO ofand, was hired last year to get the tarnished bank back on track.

But Wells Fargo's legal troubles are far from over.

"When bank workers started to raise alarms about Wells Fargo's fake account scandal, managers retaliated against us," said Kilian Colin,a former Wells Fargo employee and a member of the Committee for Better Banks, in a statement. "To make matters worse, frontline employees like us were unfairly scapegoated for trying to meet intense sales pressures.

"Today's settlement might bring some relief to consumers and workers," he added, "but it does not relinquish Wells Fargo's duty to change the workplace culture that fueled the disastrous scandal in the first place."

Wells Fargo still faces an even bigger regulatory headache: the unprecedented sanctions imposed by the Federal Reserve in early 2018 that prevent the bank from growing its assets beyond $2 trillion. If that so-called asset cap is not removed soon, Wells Fargo may not be able to make the loans required to boost profits

"That's a much bigger hurdle. That will take time," said Gerard Cassidy, a banking analyst at RBC Capital. He expects that the asset cap and other enforcement actions against Wells Fargo won't be completely removed until 2022.

Wells Fargo's stock has suffered

The Justice Department and SEC said that Friday's settlement took into account other recent fines imposed against Wells Fargo, as well as the bank's "extensive cooperation" and efforts to repair damage done to customers.

Last month, former boss John Stumpf agreed to a lifetime ban from the banking industry and a $17.5 million fine for his role in the scandals. Seven other former Wells Fargo executives were fined about $70 million for what regulators described as described as "the bank's systemic sales practices misconduct."

In February 2018, the Federal Reserve handed down unprecedented sanctions on Wells Fargo for "widespread consumer abuses," including the creation of millions of fake accounts. That penalty, which is still in place and was one of the final acts of former Fed chief Janet Yellen, prevents Wells Fargo from growing its balance sheet beyond $2 trillion.

Later in 2018, the Consumer Financial Protection Bureau and the Office of the Comptroller of the Currency fined Wells Fargo $1 billion for forcing customers to pay for car insurance they didn't need and mortgage fees they didn't owe. In some cases, Wells Fargo borrowers even had their vehicles wrongfully repossessed.

Taken together, Wells Fargo's series of scandals have seriously hurt its business . The bank's reputation is tarnished and it has been forced to spend heavily on settlements, lawyers, and fixes to its risk management system.

JPMorgan Chase JPM Bank of America BAC Wells Fargo's stock, once a favorite in the banking industry, has fallen badly out of favor. Since the scandals began in September 2016, Wells Fargo's stock is down 5%, while over the same time period the S&P 500 has soared 55%. Banking rivalsandhave more than doubled in value.

In other words, Wells Fargo has been left in the dust.