Italy's oldest bank has just clinched a multi-billion dollar rescue after flunking a test of its financial strength.

Banca Monte dei Paschi di Siena announced on Friday night that it had found a "definitive solution" to its legacy of bad loans. It will split them off into a separate entity and raise 5 billion euros ($5.6 billion) in new capital.

The value of the new shares is equivalent to five times the bank's current market capitalization. The issue will be underwritten by a consortium of global banks including JP Morgan (JPM), Bank of America (BAC), Citigroup (C), Credit Suisse (CSGKF), Deutsche Bank (DB) and Goldman Sachs (GS). That means they'll guarantee to provide the funds if not enough investors come forward to buy the shares.

The announcement came the same evening that Europe's top banking regulator, the European Banking Authority, confirmed that the Italian bank didn't have enough funds to cope with an extreme economic shock.

A total of 51 major European banks were required to take part in the so-called "stress test" to see what would happen if the economy slowed sharply. Monte dei Paschi (BMDPF) was the worst performer by far.

Related: The world's riskiest bank is in trouble

The rescue should calm fears that a looming Italian banking crisis could trigger another eurozone crisis.

Prime Minister Matteo Renzi wanted to avoid having to use taxpayers money to bail out the lender because -- under European rules -- that would have meant inflicting big losses on thousands of small investors in the bank at a politically sensitive time.

Renzi has staked his future on winning a referendum on political reform in the fall. If he loses, Italy's commitment to the euro could be called into question.

Related: Italy: Europe's next domino to fall?

Under the EBA's "stress test" scenario, a key ratio measuring the health of the bank fell into negative territory for Monte dei Paschi. That ratio remained positive for all the other banks tested.

The results, which came out after stock exchanges closed in the U.S. and Europe, could move markets on Monday. Other banks may also be forced to raise fresh funds to protect themselves in tough times.

Some experts have been expecting that Europe's top banks will have to raise tens of billions of new capital, while one academic paper estimated the shortfall at hundreds of billions of euros.

Unlike a previous stress test in 2014, there's no pass or fail grade for the banks, making the data trickier to interpret.