Credit Suisse will merge with UBS in a move approved by Swiss banking regulators after a proposed cash injection from the Swiss National Bank (SNB) failed to stabilize Credit Suisse’s rapidly declining finances.

UBS, Switzerland’s largest bank, announced Sunday it will purchase the country’s second-largest bank for 3 billion Swiss francs (U.S. $3.2 billion). Credit Suisse shareholders will receive 1 UBS share for every 22.48 Credit Suisse shares held, UBS said. The merger is expected to be completed by the end of the year, Credit Suisse said in a statement.

The deal was approved by the SNB and the Swiss Financial Market Supervisory Authority (FINMA) after Credit Suisse suffered a “crisis of confidence” as depositors raced to withdraw their funds from the bank, the regulators said in a joint statement.

“There was a risk of the bank becoming illiquid, even if it remained solvent, and it was necessary for the authorities to take action in order to prevent serious damage to the Swiss and international financial markets,” the regulators said of Credit Suisse.

Also on Sunday, the SNB announced a liquidity assistance loan of up to CHF 100 billion (U.S. $108 billion) to support the merger. Before the merger was announced, the SNB offered a loan to Credit Suisse of up to CHF 50 billion (U.S. $54 billion) to shore up its balance sheet.

The dramatic turn of events came following Credit Suisse’s disclosure of losses of CHF 7.3 billion (U.S. $8 billion) in 2022. The bank was forced to delay publication of its annual report because the U.S. Securities and Exchange Commission expressed concerns regarding its internal control over financial reporting (ICFR). The bank admitted last week its ICFR was “not effective” for the fiscal year ending 2022.

Credit Suisse, which operated as an independent bank for 167 years, at its peak in 2007 was worth $96 billion, according to a report in the Wall Street Journal.

Credit Suisse is the latest bank to require regulator intervention, following the closures of Silicon Valley Bank and Signature Bank in the United States. San Francisco-based First Republic Bank was thrown a $30 billion lifeline Thursday by 11 large U.S. banks in an effort to stop its precipitous financial slide.

Problems at Credit Suisse stretched back years, particularly with faulty risk management, as the bank strayed from its long-held expertise in wealth management to dabble in more risky ventures through its investment bank. These failures came crashing down with the twin collapses of Greensill Capital and Archegos Capital Management in March 2021, through which the bank estimated combined losses of as much as $15 billion.

In response, the bank announced a series of management shakeups followed by sweeping changes to its risk management practices, as well as layoffs and a pivot away from investment banking. All those changes, however, failed to right the ship.

“Given recent extraordinary and unprecedented circumstances, the announced merger represents the best available outcome,” Credit Suisse Board Chairman Axel Lehmann said in the bank’s release. “This has been an extremely challenging time for Credit Suisse, and while the team has worked tirelessly to address many significant legacy issues and execute on its new strategy, we are forced to reach a solution today that provides a durable outcome.”

Secretary of the U.S. Treasury Janet Yellen and Federal Reserve Board Chair Jerome Powell welcomed the announcements by Swiss authorities.

“The capital and liquidity positions of the U.S. banking system are strong, and the U.S. financial system is resilient. We have been in close contact with our international counterparts to support their implementation,” they said in a statement.