The deal -- if ratified -- should prevent a chaotic Greek exit from the euro, an unprecedented event that would have shaken Europe to its core.
"EuroSummit has unanimously reached agreement," tweeted Donald Tusk, president of the European Council and summit chairman.
Leaders of the 19 nations that use the euro hammered out the agreement at a 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 Greek 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 crash out of 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.
The agreement means the Greek government must go way beyond a reform proposal it submitted last week, by making much more profound changes to pensions, energy, labor and product markets, and by scaling up a program of privatization. It also has to overhaul its public administration and justice system.