EU leaders have struck a deal on a huge post-coronavirus recovery package following a fourth night of talks.
It involves €750bn (£677bn; $859bn) in grants and loans to counter the impact of the pandemic in the 27-member bloc.
The talks saw a split between nations hardest hit by the virus and so-called "frugal" members concerned about costs.
It is the biggest joint borrowing ever agreed by the EU. Summit chairman Charles Michel said it was a "pivotal moment" for Europe.
The deal centres on a €390bn programme of grants to member states hardest hit by the pandemic. Italy and Spain are expected to be the main recipients.
A further €360bn in low-interest loans will be available to members of the bloc.
The package will allow members to maintain spending in the aftermath of lockdowns that badly affected public finances.
It includes checks that the funds will not be misused. Recipients will have to submit spending plans to the European Commission, and a majority of states will be able to block projects.
The package will now face technical negotiations by members, and needs ratification by the European Parliament.
How did we get here?
The leaders reached agreement early on Tuesday after more than 90 hours of talks.
Mr Michel, the president of the European Council, called it "the right deal for Europe right now".
We did it! We have reached a deal on the recovery package and the European budget for 2021-2027.— Charles Michel (@eucopresident) July 21, 2020
This is a strong deal. And most importantly, the right deal for Europe right now. #EUCO pic.twitter.com/c6fQ5ppwpf
Tempers were often frayed during the negotiations. The "frugal four", Sweden, Denmark, Austria and the Netherlands, along with Finland had opposed extending €500bn in grants.
The group originally set €375bn as the limit. Other members, such as Spain and Italy, did not want to go below €400bn.
At one point French President Emmanuel Macron reportedly banged his fists on the table, as he told the "frugal four" they were putting the European project in danger.
The €390bn figure was suggested as a compromise, and "frugal" nations were reportedly won over by the promise of rebates on their EU budget contributions.
Another issue was over linking aid to the "rule of law". Hungary and Poland both threatened to veto the package if it adopted a policy of withholding funds from nations deemed to fall short of democratic principles.
How have EU European leaders reacted?
President Macron said it was a "historic day for Europe".
Mr Michel said: "We showed collective responsibility and solidarity and we show also our belief in our common future."
European Commission President Ursula von der Leyen tweeted. "Today we've taken a historic step, we all can be proud of. But other important steps remain. First and most important: to gain the support of the European Parliament. Nobody should take our European Union for granted."
Dutch Prime Minister Mark Rutte, who led the "frugal group", welcomed the agreement, but acknowledged the fractious nature of the talks. "We are all professionals, we can take a few punches," he told reporters.
Tough talks reflect power shifts
The deal was reached after marathon of negotiations that almost became the longest in EU history. The "EU enlargement" summit in Nice 20 years ago lasted only 25 minutes longer.
For leaders who had pushed for a far-reaching package, the deep frustration, including table-thumping anger from the French president, appears to have dissipated.
I asked Mr Macron whether he still felt that the "frugal four" had damaged the European project by their hard bargaining. He said, as had been reported: "It's legitimate that we have different sensibilities... If we don't take into account the realities, we'd put these leaders in a difficult spot and it would favour the populists."
The "Club Med" countries, Spain, Italy and Portugal, appear content with the smaller size of grants available. Portuguese PM Antonio Costa told us: "While it's true that it could have had a slightly bigger dimension, the recovery plan is robust enough to respond to the current estimates of the coronavirus crisis."
As for Europe's most powerful leader, German Chancellor Angela Merkel, I asked her about the new power balance in the EU. She said: "During the last negotiations [then UK Prime Minister] David Cameron's view loomed large. Now he is no longer with us, others have come to the fore."
How will the deal be funded?
The European Commission will borrow the €750bn on international markets and distribute the aid.
The deal was reached alongside agreement on the bloc's next seven-year budget, worth about €1.1tn.
The UK, which has recorded more coronavirus deaths than any other European country, left the EU in January and is not involved in the deal.
Europe's papers see mixed success
"The EU is still alive. For a change, that's good news," says Germany's Spiegel correspondent Ronald Nelles, capturing a sense of relief expressed by many.
Spain's El País calls the deal "a milestone in the budgetary evolution of the club that has never been so far on the path towards a possible fiscal union".
But several commentators note its many compromises. Charles Michel "will have to justify to the EU parliament the fact that the finished paper does not include expenditure on many research and climate projects", agrees Austria's Der Standard.
The Polish prime minister also "boasted that Poland had successfully resisted linking the portion of the money with a commitment to the fight against global warming", notes a correspondent in Gazeta Wyborcza, quoting Mateusz Morawiecki saying: "We won better rules than the European Commission proposed."
"This undeniable victory for Paris and Berlin... will leave a bitter aftertaste," says France's Les Echos. "Even hand in hand and without having to confront British roadblocks, this couple is no longer almighty in Europe."