Greece's leftwing Prime Minister Alexis Tsipras faces a showdown with rebels in his own party on Tuesday furious at his capitulation to German demands for one of the most sweeping austerity packages ever demanded of a eurozone government.
Just hours after a deal that saw Greece surrender much of its sovereignty to outside supervision in return for agreeing to talks on an 86 billion euro bailout, doubts were already emerging about whether Tsipras would be able to hold his government together.
The terms imposed by international lenders led by Germany in all-night talks at an emergency summit obliged Tsipras to abandon promises of ending austerity.
Instead he must pass legislation to cut pensions, increase value added tax, clamp down on collective bargaining agreements and put in place quasi-automatic spending constraints. In addition, he must set 50 billion euros of public sector assets aside to be sold off under the supervision of foreign lenders and get the whole package through parliament by Wednesday.
Tsipras himself, elected five months ago to end five years of suffocating austerity, said he had "fought a tough battle" and "averted the plan for financial strangulation".
But to get the accord through parliament by Wednesday's deadline, he will have to rely on votes from pro-European opposition parties, raising big questions over the future of his government and opening the prospect of snap elections.
Leftwing rebels in the ruling Syriza party, and his junior coalition partner, the right-wing Independent Greeks party, indicated they would not tear up election pledges that brought them to power in January.
"We cannot agree to that," Independent Greeks leader Panos Kammenos told reporters after meeting Tsipras. "In a parliamentary democracy, there are rules and we uphold them."
A meeting of the Syriza parliamentary group on Tuesday morning could see Energy Minister Panagiotis Lafazanis and Deputy Labour Minister Dimistris Stratoulis sacked over their opposition to the bailout.
There may also be a battle over parliament speaker Zoe Constantinopoulou, an uncompromising left-winger who also defied Tsipras over the bailout and who could create serious procedural obstacles for the package.
If the summit on Greece's third bailout had failed, Athens would have been staring into an economic abyss with its banks on the brink of collapse and the prospect of having to print a parallel currency and exit the euro.
Instead it won conditional agreement to receive a possible 86 billion euros (US$95 billion) over three years, provided its European partners are satisfied that the conditions are met.
"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 even though the summit statement insisted repeatedly that Greece must now subject much of its public policy to prior agreement by bailout monitors.
"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."
Eurozone finance ministers told officials to prepare options for bridge financing arrangements during talks on a bailout and a decision is expected by Wednesday.
Athens must meet a tight timetable for enacting unpopular reforms of value added tax, pensions, budget cuts, bankruptcy rules and an EU banking law that could be used to make big depositors take losses.
German Chancellor Angela Merkel said she could recommend "with full confidence" that the Bundestag authorize the opening of loan negotiations once the Greek parliament has approved the entire program and passed the first laws.
The Bundestag is due to vote on Greece on Friday.
Merkel's allies defended the deal, with her chief of staff, Peter Altmaier, saying Europe had won and Germany "was part of the solution — from the beginning until the end!"
But in Greece, relief was mixed with anger at Germany. "Listen, it is some sort of victory but it is a pyrrhic victory because the measures are very strict," said Marianna, 73.
Asked whether the tough conditions imposed on Greece were similar to the 1919 Versailles treaty that forced crushing reparations on a defeated Germany after World War One, Merkel said: "I won't take part in historical comparisons, especially when I didn't make them myself."
The deterioration of the Greek economy since Tsipras won office in January, and particularly in the last two weeks, had led to a much higher financing need, she said.
One senior EU official put the cost to Greece of the last two weeks of turmoil at 25 to 30 billion euros. A eurozone diplomat said it might be closer to 50 billion euros.
Malta's Prime Minister Joseph Muscat said Greece had been "humiliated", mostly as a result of its refusal to take an offer made to it two weeks ago, and he said the talks had been brutal.
"It was not pretty to watch," he said.
Tsipras accepted a compromise on German-led demands for the sequestration of Greek state assets worth 50 billion euros, including recapitalized 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 opposition to a full role for the International Monetary Fund in the next bailout, which Merkel had insisted on 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, Labor Minister Panos Skourletis said the terms were unviable and would lead to new elections this year.
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 its tough terms on Tsipras, Germany dropped a proposal to make Greece take a "time-out" from the eurozone that many said resembled a forced ejection if it failed to meet the conditions.
Tsipras was subjected to a 17-hour browbeating by leaders furious that he had spurned their previous bailout offer on more favorable terms in June and had held a referendum last week to reject it. Only France and Italy worked to try to soften the terms being imposed on Greece.
Some diplomats questioned whether it was feasible to rush the package through the Greek parliament in three days and even if this week's rescue succeeds, some also question whether Greece will stay the course on a three-year program.
Eurozone finance ministers were tasked with finding sources of immediate bridge funding for Greece to prevent it defaulting on a key payment to the ECB next Monday.
Greece needs 7 billion euros by July 20, when it must make a bond redemption to the ECB, and 12 billion euros by mid-August when another ECB payment falls due.
The ECB on Monday maintained emergency funding for Greek banks to keep them just afloat this week, a banking source said.