Wells Fargo chief executive Tim Sloan at a House Financial Services Committee hearing earlier this month. Sloan stepped down Thursday. (Erin Scott/Reuters)

For months, the bad headlines ricocheted through Wells Fargo.

Lawmakers lashed out at the bank for improperly foreclosing on hundreds of customers, then it was deluged with complaints from customers locked out of their accounts. Regulators grew increasingly frustrated with the pace of Wells Fargo’s progress in fixing the internal systems that led to a series of customer abuses.

By the time the company’s chief executive, Tim Sloan, appeared before a hostile House committee earlier this month, some banking industry executives were beginning to wonder how much more the bank — and Sloan — could take. Still, Sloan’s abrupt announcement late Thursday that he would be stepping down caught many by surprise.

Wells Fargo’s largest shareholder, Warren Buffet of Berkshire Hathaway, told CNBC hours before the announcement he had “100 percent” confidence in Sloan.

Wells Fargo’s board began a quest to replace Sloan, 58, on Friday, focused on finding an outsider to lead one of the country’s largest banks.

Sloan, who has spent more than 31 years at Wells Fargo, replaced another company veteran, John Stumpf, in 2016. Stumpf had led the company for nearly 10 years and had spent more than 30 years at the bank.

C. Allen Parker, the bank’s general counsel, is serving as interim CEO and president.

Leading Wells Fargo should be one of the most coveted positions in the banking world. The bank, the fourth-largest in the country, reported a profit of more than $20 billion last year and has more than 70 million customers. Its national footprint and iconic stagecoach would automatically make Wells Fargo’s new CEO one of the most influential people in the banking world.

But Sloan’s replacement will face a herculean task.

That executive must not only master running a large organization but also quickly develop a relationship with some of the bank’s harshest critics on Capitol Hill. That would include Sen. Elizabeth Warren (D-Mass.), a high-profile 2020 presidential contender who led the congressional pressure to have Sloan fired.

The bank’s critics in Congress say they will continue scrutiny of its actions. “I will … ensure that the bank is held fully accountable for its wrongdoing, including by continuing to press regulators to utilize all the enforcement tools at their disposal," Rep. Maxine Waters (D-Calif.), chair of the House Financial Services Committee, said in a statement.

Rep. Katie Porter (D-Calif.), a new member of the Financial Services Committee, was among those who gave Sloan a chilly reception earlier this month. “Instead of rearranging deck chairs on the Titanic, maybe try a new boat,” she tweeted Friday in response to Sloan’s departure.

Wells Fargo escaped many of the worst headlines after the global financial crisis, only to face a series of self-inflicted wounds over the past two years. The bank’s struggles began with its admission in 2016 that it had opened millions of accounts that customers didn’t want, and its problems have ballooned as regulators have identified a pattern of consumer abuses. The bank had improperly repossessed thousands of cars and mistakenly foreclosed on hundreds of other customers, the company recently acknowledged.

“The problem is that they need to stay out of the news and they haven’t been able to do it,” said Isaac Boltansky, a Washington policy analyst for the investment firm Compass Point Research & Trading.

One of most difficult tasks facing the company’s new leader will be repairing the bank’s relationship with its regulators. The Office of the Comptroller of the Currency, led by a former banker and Trump appointee, recently said it was “disappointed” in the bank’s efforts to address its problems.

“It was clear Tim Sloan and Wells Fargo has no friends in D.C.,” said Ed Mills, Washington policy analyst and managing director at Raymond James. “If banks have a friend in D.C. these days it’s the OCC. For even the Trump regulatory team to [levy] unsolicited criticism" is a troubling sign for Wells Fargo, Mills said.

The bank’s relationship with the Federal Reserve, another important regulator, is also frayed. The Fed levied an unprecedented penalty against the bank last year, ordering it not to grow larger than its $1.95 trillion in assets until it addressed its problems. Wells Fargo initially said it expected the cap on its growth to be lifted this year but has since pushed that back to 2020.

Aside from reassuring lawmakers and regulators, Wells Fargo must also repair its image with skeptical customers.

Stanley Owens, 45, of Orlando said he closed his Wells Fargo checking and savings accounts late last year after growing frustrated with efforts to get answers about fees on his monthly statements.

“I say good luck to whoever they find,” he said. “Personally, I just gave up.”