Cyprus has agreed to shrink its bloated financial industry and tap big depositors at its two leading banks for billions of euros, clearing the way for a €10 billion European Union bailout.
The development staved off a disorderly collapse of Cyprus' banks and appears to have calmed fears that this tiny island nation's meltdown could inflame problems elsewhere in Europe.
The deal was struck early Monday after days of frantic negotiations that followed the rejection by Cypriot lawmakers of Plan A. That proposal, unveiled little over a week ago, would have imposed a tax on all account holders to raise funds to recapitalize the failing banks.
The new bailout plan will protect all deposits of less than €100,000 but is likely to mean much bigger losses for account holders with more than €100,000 at the two biggest banks -- the Bank of Cyprus and Popular Bank of Cyprus.
Popular Bank will be broken up immediately. Its viable assets will be integrated into the Bank of Cyprus, and its non-performing loans will be moved into a "bad bank" to be wound down.
The "haircut" for Popular Bank depositors will raise about €4.2 billion, while shareholders and bondholders are likely to be wiped out. The scale of depositors' contribution to the restructuring of Bank of Cyprus has yet to be fixed.
Jeroen Dijsselbloem, who chaired the critical meeting of eurozone finance ministers Sunday, said the plan had the support of all eurozone member states, the European Central Bank and the International Monetary Fund.
"We have agreed," Cyprus President Nicos Anastasiades told reporters after the meeting in Brussels. He said the deal was in "the best interests of the Cyprus people and the EU as a whole."
Without a deal, the tiny state risked losing emergency funding from the ECB as early as Tuesday. That would have meant financial collapse and almost certain exit from the eurozone.
Related: What happens if the banks fail?
Cyprus, which accounts for just 0.2% of the eurozone economy, needed to find a way to raise enough to put the Bank of Cyprus on sound footing and to pay for the winding up of Popular Bank in order to qualify for the €10 billion on offer from the EU.
The original proposal for a one-off levy of up to 10% on all bank accounts, including deposits up to €100,000 covered by a national guarantee program, outraged Cypriots and prompted condemnation for trashing the principle that ordinary savers should not pay for bank failures.
Cypriots have been queuing at cash machines since the original proposal was first announced on March 16. Banks have been shut since then.
The Cyprus parliament passed bills last week on restructuring the banks, as well as controls on the free movement of capital, which may still be needed to prevent a disastrous run on the country's banks. Smaller daily withdrawal limits have been introduced at some ATMs.
Dijsselbloem said a decision on when and how the banks would reopen would be taken later Monday following discussions between Cyprus and officials from the ECB, IMF and EU.
Related: Cyprus' natural gas gold mine
Cyprus has been brought to its knees by the losses that its oversized banking sector sustained on investments in Greece, as well as a deep recession. Total deposits of around €70 billion euros are about four times the size of the economy.
Eurozone policymakers wanted Cyprus to stump up cash from its banks as part of the rescue to ensure the country's debt doesn't become unsustainable.
And the EU believes wealthy foreigners who have profited from Cyprus' low tax rates should contribute. More than half of bank deposits are held by foreigners, many of them Russian.
Russia has come to Cyprus' aid in the past with a €2.5 billion loan. EU officials said they hoped Russia would make a contribution to the new rescue effort by extending the term of that loan and/or reducing the interest rate.
In the end, the total size of the bailout was not immediately clear. The EU portion will not exceed €10 billion, but officials on Monday declined to specify how much Cyprus would contribute.
As part of the program, Cyprus will also have to raise taxes on capital gains and companies, introduce structural reforms and privatize some state assets. It has also agreed to an independent audit of anti-money laundering efforts in the banking system.