Europe has offered Greece a new $96 billion bailout after its government agreed to enact deep economic reforms under close supervision by its creditors.
The rescue -- Greece's third since 2010 - should secure its place in the euro, for now. The country's potential exit from the currency union would have shaken Europe to its core.
Greece agreed to significant economic reforms: Pension cuts and higher taxes, as well as the sale of some government assets. The key to the deal: Proof that Greece will follow through.
"Eurozone leaders have agreed in principle that they are ready to start negotiations on a [new bailout]," said Donald Tusk, who chaired an emergency summit of all 19 nations that use the euro.
Greece's Parliament must approve these measures by Wednesday. In addition, Europe will assign monitors to ensure that Greece will also have to give up control of the proceeds from government sales, with the bulk being earmarked for debt payments.
Greece had been pushing for some of its massive debt load to be canceled. Europe rejected that, but said it would consider easing the terms with longer grace periods.
Greeks unhappy but resigned: 'What can we do?'
Still, the deal is just a proposal, and it does not mark an immediate end to the crisis. It could face resistance in Greece's Parliament.
And Greece desperately needs the European Central Bank to restart money flows to re-open up its shuttered banks. The ECB however said Monday that it was not ready to do so yet.
The leaders hammered out the agreement at the marathon overnight meeting in Brussels, after weeks of frantic diplomacy sparked by Greece walking away from a previous bailout program.
That decision left it without the cash to make a payment to the International Monetary Fund, triggered the closure of its banks, and sent the economy into free fall.
Fast running out of money, Greece faced an awful choice: Accept the conditions demanded by the only people willing to lend it money, or leave the euro.
Speculation about the currency should now fade, but it's not clear how soon the money the country desperately needs will flow, and when its banks will reopen.
Related: Read the full deal document
Finance officials will reconvene later Monday to talk about how to support Greece while the details of the bailout are being negotiated. That process could take weeks.
The conditions are particularly tough for two main reasons.
First, the economy has deteriorated sharply in recent weeks, damaging Greece's already fragile finances still further.
Second, there was a complete breakdown in trust between Greek Prime Minister Alexis Tsipras and other European leaders. That was largely because of a series of U-turns he performed, and his decision to call a referendum to reject reforms he then signed up to days later.
That made for hard talking this weekend. The summit ran for 17 hours, and that was after finance officials had spent 14 hours preparing the ground.
Under pressure from skeptical voters, some European leaders wanted ironclad guarantees that they wouldn't be throwing good money after bad. Europe and the IMF have already lent Greece about 233 billion euros since 2010.
Monday's deal requires Greece to give access to bailout monitors on the ground in Athens -- including officials from the IMF, a point Tsipras resisted to the last.
He was elected on promises to reverse austerity and end intrusive monitoring, and the agreement will raise questions about whether he can continue in his post.
Related: Inside Greece's health care crisis
But without a new bailout, Tsipras knew Greece's descent into economic chaos would accelerate, bringing the country ever close to exit from the euro.
Greece's banks have been shut for two weeks, and cash withdrawals are capped. The vital tourism industry is suffering. People are spending less, some public services have stopped charging, and the healthcare system is running out of imported medicines.
Greece needs to pay pensions and wages this week, and make a big debt repayment to the European Central Bank next week. Without an injection of funds fast, it would have to issue IOUs, a first step to printing its own currency.
The country isn't home and dry yet. Tsipras has to push a first package of reforms -- including tax changes and pension reforms -- through parliament by Wednesday.
And it's not clear whether that will be enough to persuade the ECB to ease restrictions on funding for Greek banks imposed after the government walked out of talks in late June.
Special report: Greece in Crisis
Assuming Greece accepts a broader overhaul of the economy, there are still other potential roadblocks standing in the way of a third bailout.
A handful of other eurozone countries, including Germany and Finland, will need to win votes in their parliaments this week on a new rescue. Only then can formal negotiations begin.
-- CNN's Anna Stewart and Saskya Vandoorne contributed to this article