Greece reached a deal with its European creditors Monday that avoids an exit from the euro and the global financial chaos that prospect had raised. The deal calls for Greece, already reeling from harsh austerity measures, to cut back even further in exchange for more loans without which its financial system would surely collapse.

French President Francois Hollande said the Greek parliament would convene within hours to adopt the reforms called for in the plan, and he celebrated Greece’s continued membership in the euro. For the eurozone to have lost Greece, Hollande said, would have been to lose “the heart of our civilization.”

The agreement came after months of often bitter negotiations and a summit that stretched from Sunday afternoon well into Monday morning. Greek Prime Minister Alexis Tsipras had been holding out for a better deal to sell to his reluctant legislature in Athens this week, even as financial collapse grew closer by the day.

A breakthrough came in a meeting between Tsipras, Hollande, German Chancellor Angela Merkel and EU President Donald Tusk, after the threat of expulsion from the euro put intense pressure on Tsipras to swallow politically unpalatable austerity measures in exchange for the country’s third bailout in five years.

“We took the responsibility of the decision to be able to avert the harshest outcome,” Tsipras said. “We managed to avert the demand to transfer Greek assets abroad, to avert the collapse of the banking system.”

The deal includes commitments from Tsipras to push a drastic austerity program including pension, market and privatization reforms through parliament by Wednesday. In return, the 18 other eurozone leaders committed to start talks on a new bailout program that should stave off the imminent collapse of the Greek financial system.

A Cypriot official said the creditors would look into bridge financing for Greece later Monday, suggesting that the political decision could pave the way for the European Central Bank to extend emergency liquidity assistance to Greek banks. Without it, they risk running out of cash this week. The official spoke only on condition of anonymity because he was not authorized to discuss the deal publicly.

If the talks had failed, Greece could have faced bankruptcy and a possible exit from the euro, the European single currency that the country has been a part of since 2002. No country has ever left the joint currency, which launched in 1999, and there is no mechanism in place for one to do so.

Greece had requested a three-year, 53.5 billion-euro ($59.5 billion) financial package, but that number grew larger by the tens of billions as the negotiations dragged on and the leaders calculated how much Greece will need to stay solvent.

A discussion paper put to eurozone leaders Sunday and obtained by The Associated Press spoke of a potential “time-out from the euro area” for Greece if no agreement could be found.

Greece has received two previous bailouts, totaling 240 billion euros ($268 billion), in return for deep spending cuts, tax increases and reforms from successive governments. Although the country’s annual budget deficit has come down dramatically, Greece’s debt burden has increased as the economy has shrunk by a quarter.

The Greek government has made getting some form of debt relief a priority and hopes that a comprehensive solution will involve European creditors at least agreeing to delayed repayments or lower interest rates.

Greek debt stands at around 320 billion euros ($357 billion) — a staggering 180 percent or so of the country’s annual gross domestic product. Few economists think that debt will ever be fully repaid. Last week, the International Monetary Fund said Greece’s debt will need to be restructured.