Euro zone leaders clinched a deal with Greece on Monday to negotiate a third bailout to keep the near-bankrupt country in the euro zone after all-night talks at an emergency summit.
However, the terms imposed by international lenders led by Germany may put more pressure on leftist Prime Minister Alexis Tsipras, fracture the government and cause an outcry in Greece.
If the summit had failed, Greece would have been staring into an economic abyss with its shuttered banks on the brink of collapse and the prospect of having to print a parallel currency and in time, exit the European monetary union.
"The agreement was laborious, but it has been concluded. There is no Grexit," European Commission President Jean-Claude Juncker told a news conference after 17 hours of bargaining.
He dismissed suggestions that Tsipras had been humiliated by accepting far-reaching, German-inspired terms he long promised to resist.
"In this compromise, there are no winners and no losers," Juncker said. "I don't think the Greek people have been humiliated, nor that the other Europeans have lost face. It is a typical European arrangement."
Tsipras himself, elected five months ago to end five years of suffocating austerity, insisted he and his team "fought a tough battle" but had to make difficult decisions.
Instead, he won conditional agreement to receive a possible 86 billion euros ($95.29 billion) over three years, along with an assurance that euro zone finance ministers would start within hours discussing ways to bridge a funding gap for Greece until a bailout - subject to parliamentary approvals - is finally ready.
German Chancellor Angela Merkel said she could recommend "with full confidence" that the Bundestag authorise the opening of loan negotiations with Athens once the Greek parliament has approved the entire programme and enacted the first laws.
Asked whether the tough conditions imposed on a desperate Greece were not similar to the 1919 Versailles treaty that forced crushing reparations on a defeated Germany after World War One, she said: "I won't take part in historical comparisons, especially when I didn't make them myself."
EU officials said Tsipras finally accepted a compromise on German-led demands for the sequestration of Greek state assets worth 50 billion euros - including recapitalised banks - in a trust fund beyond government reach, to be sold off primarily to pay down debt. In a gesture to Greece, some 12.5 billion euros of the proceeds would go to investment in Greece, Merkel said.
The Greek leader had to drop his resistance to a full role for the International Monetary Fund in a proposed 86 billion euro bailout, which Merkel has declared essential to win parliamentary backing in Berlin.
In a sign of how hard it may be for Tsipras to convince his own Syriza party to accept the deal, Labour Minister Panos Skourletis said the terms were unviable and would lead to new elections this year.
As the hours ticked away overnight, most of the leaders were forced to cool their heels, playing computer games or taking a nap in their delegation offices while Tusk and the leaders of Germany, France and Greece met several times privately to try to cut through the final knots.
Tsipras will now have to rush swathes of legislation through parliament this week to convince his 18 partners to release bridging funds to avert a state bankruptcy and just to begin negotiations on a three-year loan.
Six sweeping measures including spending cuts, tax hikes and pension reforms must be enacted by Wednesday night and the entire package endorsed by parliament before talks can start, the leaders decided.
In almost the only concession after imposing a tough set of terms on Tsipras, Germany dropped a proposal to make Greece take a "time-out" from the euro zone that many said resembled a forced ejection if it failed to meet the conditions.
Tsipras had said on arrival in Brussels on Sunday he wanted "another honest compromise" to keep Europe united. Instead, he was subjected to a 17-hour browbeating by leaders furious that he had spurned their previous bailout offer on more favourable terms in June and held a referendum last week to reject it.
Only France and Italy worked to try to soften the terms being imposed on Greece.
One senior EU official calculated the cost to the Greek state of the last two weeks of political and economic turmoil at 25 to 30 billion euros.
Merkel, whose country is the biggest contributor to euro zone bailouts, said from the start that she would drive a hard bargain against a backdrop of mounting opposition at home to more aid for Greece.
If Greece meets the conditions, the German parliament would meet on Thursday to mandate Merkel and Finance Minister Wolfgang Schaeuble to open the talks on a new loan. Then Eurogroup finance ministers could formally launch the negotiations.
Perhaps the toughest condition for Tsipras to swallow was Germany's insistence that Greek state assets worth up to 50 billion euros be placed in a trust fund beyond government reach to be sold off with proceeds going directly to pay down debt.
Berlin initially wanted to use a structure in Luxembourg managed by its own national development bank, KfW, but diplomats said it was flexible on the location.
One diplomat said that was tantamount to turning Greece into a "German protectorate", stripping it of more sovereignty.
But Merkel declared the matter a "red line" for Germany.
For his part, Tsipras demanded a stronger commitment by the creditors to restructure Greek debt to make it sustainable in the medium-term. That could be his only hope of selling such a deeply unpalatable package to his own supporters and the public.
An EU official said several options were under consideration to give Greece bridging funds once it passed the laws, but no final decision was taken.
They included releasing European Central Bank profits on Greek bonds, tapping an emergency fund run by the European Commission, or bilateral loans from friendly countries such as France. Two French sources denied any bridging loan was planned.
Finance ministers said Greece needed 7 billion euros of funding by July 20, when it must make a crucial bond redemption to the ECB, and a total of 12 billion euros by mid-August when another ECB payment falls due.
Some diplomats questioned whether it was feasible to rush the package through the Greek parliament in just three days. Tsipras is set to sack ministers who did not support his negotiating position in a vote last Friday and make dissident lawmakers in his Syriza party resign their seats, people close to the government said. ($1 = 0.9025 euros)