Donald Tusk: "After 17 hours of negotiations we have reached agreement"
Eurozone leaders have agreed to offer Greece a third bailout, after marathon talks in Brussels.
Amid one of the worst crises in the EU's history, the head of the European Commission said the risk of Greece leaving the eurozone had been averted.
Greek Prime Minister Alexis Tsipras said that after a "tough battle", Greece had secured debt restructuring and a "growth package".
Greece will now have to pass reforms demanded by the eurozone by Wednesday.
These include measures to streamline pensions, raise tax revenue and liberalise the labour market.
An EU statement spoke of up to €86bn (£61bn) of financing for Greece over three years.
Though it included an offer to reschedule Greek debt repayments "if necessary", there was no provision for the reduction in Greek debt - or so-called "haircut" - that the Greek government had sought.
Parliaments in several eurozone states also have to approve any new bailout.
"There will not be a 'Grexit'," said European Commission chief Jean-Claude Juncker, referring to the fear that if there had been no deal, Greece could have crashed out of the euro.
Mr Tsipras also said he had the "belief and the hope that... the possibility of 'Grexit' is in the past".
"The deal is difficult but we averted the pursuit to move state assets abroad," he said. "We averted the plan for a financial strangulation and for the collapse of the banking system."
Greeks had an anxious wait as talks in Brussels dragged on
Athens has been offered a third bailout. Bankruptcy - the spectre of a failed state - has been avoided, and Greece will stay inside the euro. But the deal has left many Greeks humiliated. It is not just the ranks of the left that are using the word "surrender".
Greek Prime Minister Alexis Tsipras will have to rush key measures on pension reforms, tax increases and a debt repayment fund through parliament. It will be a bruising process. Only then will bridging loans be released that will enable Greece to meet a payment to the European Central Bank next Monday.
As it is, the deal will almost certainly lead to snap elections. Mr Tsipras will reshuffle his cabinet and discard those cabinet ministers who opposed his latest proposal.
Jeroen Dijsselbloem, the head of the eurozone group of finance ministers, said the agreement included a €50bn Greece-based fund that will privatise or manage Greek assets. Out of that €50bn, €25bn would be used to recapitalise Greek banks, he said.
Greek banks have been closed for two weeks, with withdrawals at cash machines limited to €60 per day. The economy has been put under increasing strain, with some businesses closing and others struggling to pay suppliers.
Monday saw the European Central Bank maintain its cap on emergency funds being provided to Greek banks, meaning they will stay shut for now to prevent them running out of funds.
There have been mixed views on the streets of Athens to the new agreement
Eurozone finance ministers are due to meet later on Monday to discuss providing "bridge financing" that would cover Greece's short-term needs.
"The road will be long, and judging by the negotiations tonight, difficult," German Chancellor Angela Merkel said on Monday morning.
French President Francois Hollande said the agreement had allowed Europe to "preserve integrity and solidarity".
"We also had to show that Europe is capable of solving a crisis that has menaced the eurozone for several years," he said.
Mr Juncker said: "In this compromise, there are no winners and no losers.
"I don't think the Greek people have been humiliated, nor that the other Europeans have lost face. It is a typical European arrangement."
However, many Greeks and others who thought that unduly harsh terms were being imposed on Greece have expressed their widespread anger online using the hashtag #ThisIsACoup.
Mr Tsipras came to power after his left-wing Syriza party won elections in January on a promise to end austerity. Greece has already received two bailouts totalling €240bn since 2010.