Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

European leaders sealed a deal with near-bankrupt Greece early Monday on a third debt bailout that will keep it in the euro currency zone.

"Today we had only one objective, to reach an agreement, after 17 hours of negotiations we have finally reached it," European Council President Donald Tusk told reporters after exhausting all-night talks.

EuroSummit has unanimously reached agreement. All ready to go for ESM programme for #Greece with serious reforms & financial support — Donald Tusk (@eucopresident) July 13, 2015

Jean-Claude Juncker, president of the European Commission, announced: "There is no Grexit."

However, the deal — which includes the privatization of some state assets — needs to be ratified by a reluctant legislature in Athens as well as parliaments in other eurozone countries.

Tough conditions imposed by international lenders, led by Germany, could bring down Prime Minister Alexis Tsipras' leftist government and cause an outcry in Greece.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Tsipras was under intense pressure as Greek banks were on the brink of collapse and the country faced the prospect of having to print a parallel currency and quit the European monetary union.

"There are strict conditions to be met," said Tusk, who joked that the leaders had reached "a-Greek-ment" — a comment that led to the hashtag #Greekment trending on Twitter.

German Chancellor Angela Merkel warned: “Essential changes have to be made, for example a complete reform of the pension system," adding that Greece must also move forward on privatization and labor market changes.

German Chancellor Angela Merkel holds a press conference at the end of talks over the Greek debt crisis in Brussels on Monday. JEAN-CHRISTOPHE VERHAEGEN / AFP - Getty Images

She also warned there was no prospect of a cut in the overall debt owed by Greece.

Germany also insisted 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.

The deal followed days of negotiations in which Tsipras held out for better terms.

The Financial Times newspaper reported that talks almost collapsed at around 6 a.m. - leaving Greece to exit the euro - but Tusk persuaded Merkel and Tsipras to continue negotiations.

Merkel is truly the iron chancellor. She discusses Greece as if it is a colony...How can Tsipras survive? — Jim Cramer (@jimcramer) July 13, 2015

Christine Lagarde, director of the International Monetary Fund, said: "It has been a laborious night but I think it’s a good step to rebuild confidence.

She added: "There will be many more steps."

Related: Deal or Not, Greece Is Running Out of Fruit

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.

Finance ministers said Greece needed 7 billion euros of funding by July 20, when it must make a crucial bond redemption to the European Central Bank, and a total of 12 billion euros by mid-August when another ECB payment falls due.