Greece has agreed to tough reforms after marathon talks with eurozone leaders in return for a three-year bailout worth up to 86 billion euros ($129 billion).

The terms imposed by international lenders, led by Germany in 17 hours of talks, obliged prime minister Alexis Tsipras to abandon promises of ending austerity and could fracture his government and cause an outcry in Greece.

To get the accord through parliament by the deadline on Wednesday, Mr Tsipras will have to rely on votes from pro-European opposition parties, raising big question marks over the future of his government and opening the prospect of snap elections.

As part of the deal, eurozone finance ministers will discuss how to keep Greece financed during the time it will need to gain parliamentary approval, but none of the options appear easy, officials said.

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.

This will be Greece's third rescue program in five years, which will be funded by the European Stability Mechanism, the EU's bailout fund.

Mr Tsipras emerged from the talks saying his government "faced difficult decisions".

"We took the responsibility for the decision to avert the most extreme plans by conservative circles in Europe," he said.

"We averted a plan of a financial choking and banking collapse."

He said a growth package of 35 billion euros and debt restructuring "will make Grexit a thing of the past".

European shares surged on the news of the deal which prevented Greece from crashing out of the European single currency.

"Clearly the Europe of austerity has won," Greece's reform minister George Katrougalos told BBC radio.

"Either we are going to accept these draconian measures or it is the sudden death of our economy through the continuation of the closure of the banks.

"So it is an agreement that is practically forced upon us."

European Council president Donald Tusk said terms of the deal meant strict conditions needed to be met.

"The approval of several national parliaments, including the Greek parliament, is now needed for negotiations on an ESM [European Stability Mechanism] program to formally begin.

"Nevertheless, the decision gives Greece a chance to get back on track with the support of European partners.

"It also avoids the social, economic and political consequences that a negative outcome would have brought."

Long and difficult road ahead: Merkel

"The road will be long, and judging by the negotiations tonight, difficult," German chancellor Angela Merkel said.

Greece drama unfolds June 28: Greek banks are closed, withdrawal limits are set to 60 euros ($89) a day July 5: Greek voters reject terms of a bailout proposition with 61.31 per cent voting "No", boosting prime minister Alexis Tsipras at the negotiating table

July 6: Yanis Varoufakis resigns as Greek finance minister to improve relations with eurozone creditor countries, and is replaced by Euclid Tsakalotos, who has been steering talks with EU-IMF creditors

July 7: Eurozone finance ministers meet in Brussels but no proposal reached European Commission head Jean-Claude Juncker, who is not in favour of Greece leaving the EU, warns a Grexit scenario has been prepared "in detail"



July 8:

Mr Tsipras is greeted by boos and cheers at the European parliament, says Greece will submit "credible" reform plans and wants to prevent a "divided Europe". His speech draws a mix of boos and cheers from European MPs July 11: Greek parliament backs new reform plan, submits proposals to the EU for consideration July 12: Eurozone finance ministers meet for talks, planned EUCO summit delayed July 13: Greece agrees to tough reforms in return for a three-year bailout worth up to 86 billion euros

Asked whether the tough conditions imposed on Greece were not similar to the 1919 Versailles Treaty that forced crushing reparations on a defeated Germany after World War I, Ms Merkel said: "I won't take part in historical comparisons, especially when I didn't make them myself."

US treasury secretary Jack Lew said the deal was good for the global economy.

"Today's agreement between Greece and its creditors is an important step forward," he said in a statement.

Greece applied last week for a third program from the eurozone's bailout fund after its previous bailout expired on June 30, leaving it without international financial assistance for the first time in years.

Greek banks have been closed for nearly two weeks and there were fears they were about to run dry due to a lack of extra funding by the European Central Bank.

This would mean Athens would have had to print its own currency and effectively leave the euro.

But Eurogroup head Jeroen Dijsselbloem said eurozone finance ministers had not yet been able to find a solution to provide short-term funding.

"This is very complex, we looked at a number of possibilities," he said.

"We have not yet found the 'golden key' to solve this issue."

The Greek finance ministry confirmed banks would remain closed until at least July 15 inclusive.

Former finance minister likens deal to 'new Versailles Treaty'

In his first interview since resigning earlier this month, former Greek finance minister Yanis Varoufakis described the bailout deal agreed to by Mr Tsipras as "a new Versailles Treaty".

"This is the politics of humiliation," he told Radio National's Late Night Live.

"The troika have made sure that they will make him eat every single word that he uttered in criticism of the troika over the last five years. Not just these six months we've been in government, but in the years prior to that.

"This has nothing to do with economics. It has nothing to do with putting Greece on the way to recovery.

"This is a new Versailles Treaty that is haunting Europe again, and the prime minister knows it. He knows that he's damned if he does and he's damned if he doesn't."

Mr Varoufakis rejected the deal in the strongest possible terms, comparing it to the 1967 coup d'etat that installed a military dictatorship in the Mediterranean nation.

"In the coup d'etat the choice of weapon used in order to bring down democracy then was the tanks. Well, this time it was the banks. The banks were used by foreign powers to take over the government," he said.

Sorry, this video has expired Syriza MP Stelios Kouloglou speaks to Auskar Surbakti

"The difference is that this time they're taking over all public property."

Mr Varoufakis suggested that Mr Tsipras may call a snap election rather than bring the deal before the Greek parliament, saying he would be "very surprised" if Mr Tsipras wanted to stay on as prime minister.

He insisted, however, that he and Mr Tsipras remain on good terms, and that he has kept a low profile over the last week in order to support Mr Tsipras and his successor in the finance ministry, Euclid Tsakolotos.

"I jumped more than I was pushed," he said, describing his resignation in the immediate aftermath of the 'no' vote in the July 6 referendum on bailout terms similar to those accepted on Monday.

Syriza member of the European parliament Stelios Kouloglou said Mr Tsipras was blackmailed into accepting the deal with eurozone leaders.

"The style was very colonial, like take it or leave it, we are the bosses," he told the ABC's The World program.

"You cannot find one serious economist in the world who will tell you that after six years of recession, you need more austerity."

ABC/wires