ROME — European Union leaders on Tuesday provided a vital lifeline for the Mediterranean countries that have sometimes felt abandoned by Brussels amid the coronavirus pandemic, reaching a deal to pump money into their hard-hit economies.

Though the rescue package was celebrated by nearly all the leaders after four days of tense negotiations, the reaction was perhaps most notable in Europe’s south — particularly in Italy, where months ago politicians on the left and the right expressed fury at the disunified European response.

Under the deal struck Tuesday, Italy will receive the largest share of the stimulus money, with Spain receiving the second-largest. Nearly as important as the result were the political dynamics: Though some northern nations wanted a smaller rescue package with tighter conditions, German Chancellor Angela Merkel and French President Emmanuel Macron pushed back, smoothing over a north-south divide that has plagued previous crises.

“It’s a historic day for Italy,” Prime Minister Giuseppe Conte said. “We have a chance to relaunch Italy with strength, to change the face of our country.”

He said Italy, which will get $240 billion of the $859 billion recovery fund, would receive even more than had been earmarked in earlier proposals. That money will come in the form of loans and grants — the grants being more important for southern European countries, which are already saddled with high levels of debt.

In Greece, whose economy last decade required a bailout with onerous E.U.-dictated terms, Prime Minister Kyriakos Mitsotakis called the stimulus deal a “national success.” Spanish Prime Minister Pedro Sánchez, whose country is set to receive $160 billion, said, “One of the most brilliant pages in E.U. history has been written.”

In April, the bloc’s finance ministers approved a smaller stimulus package, but Italy and other countries walked away, saying a broader effort — involving the joint issuing of debt — was still needed. In the deal reached Tuesday, Europe plans to raise money by selling bonds, the first time it has used such a mechanism.

Europe’s southern countries, as well as France, are forecast to see their economies contract in the range of 10 percent this year. Spain and Italy emerged as coronavirus epicenters in the spring, and both imposed lengthy, rigid lockdowns that brought business activity to a near-halt. Even though the virus’s spread has since slowed dramatically, southern European economies are being battered by a collapse in tourism.

When debate about the pandemic response kicked off, many southern Europeans were fearful that any ambitious plan might unravel amid rancor — in a replay of the divisions among E.U. nations over sharing the duties of accepting asylum seekers during the height of the migration crisis.

In Italy, in March and April, even reliably pro-European politicians warned that the future of the bloc was at risk. France and Germany were initially reluctant to share medical equipment, and Italy’s proposal for “corona bonds” was shot down.

Nathalie Tocci, director of the Italian International Affairs Institute, said Tuesday that the tune in Rome toward Europe has “changed fairly dramatically” since then. She said this European deal would prove to be the enduring memory.

“The E.U. had been doing the bare minimum to survive, and this time it didn’t,” she said. “All of the divisions that we’re so used to talking about, notwithstanding all of that, we did it.”

The Euroskeptic, far-right League party remains Italy’s most popular, and its leader, Matteo Salvini, criticized the rescue package as a “big rip-off” in which Rome would be subservient to Brussels. But both the League and Salvini personally have bled support during the pandemic, while the centrist Conte has risen in popularity.

Matteo Renzi, a former Italian prime minister and a member of Conte’s governing coalition, said the deal was an “excellent result” for Italy and a “masterpiece” for Europe.

“The sovereigntists lose,” Renzi wrote on Twitter. “The agreement shows that a pro-European government is good for Italy.”

Stefano Pitrelli contributed to this report.