VERONA, Italy — One of Europe’s most enduring political disputes came to a formal end Friday, with Greece’s Parliament approving an agreement that allows Macedonia to change its name and eventually join NATO and the European Union.

The deal, approved in a 153-to-146 vote, was the final step in a precarious seven-month process that has included street protests, nationalist opposition, alleged Russian attempts at interference and acrimonious paths to ratification in both countries.

Widely supported by the United States and E.U. leaders, the agreement calls for Macedonia to change its name to North Macedonia, while Greece, in exchange, drops long-held opposition that has prevented its neighbor from integrating more formally with Europe.

U.S. officials have said the deal has the chance to transform and stabilize the Balkans, a region that lags economically behind the rest of Europe and one where Russia battles with the West for influence. But opinion polls indicate that nearly 7 in 10 Greeks oppose the accord, and many accuse Prime Minister Alexis Tsipras of pulling his party away from its populist roots while ramming through a deal that has won him acclaim from abroad.

The dispute over Macedonia’s name has burned for nearly three decades, since the country was formed during the breakup of Yugoslavia. The name issue became a proxy for a wider debate over national identity in a region with a proud and deep history that dates to Alexander the Great.

The outcome Friday was cheered by pro-Europeans as a rare victory for a continent dealing with the spread of nationalism and the chaos of Britain’s pending departure from the E.U. The vote was also a blow to Russia, which had allegedly tried to stoke opposition to the name deal with a disinformation campaign and offers of money and bribes.

The agreement was orchestrated by a pair of left-leaning leaders, Tsipras and Macedonia’s Zoran Zaev, who faced fierce political fights in recent months and who were accused of betraying their countries’ interests. On the way to finalizing the deal, Tsipras lost his parliamentary majority as a small coalition partner revolted, and he only narrowly survived a no-
confidence vote. On Sunday, tens of thousands rallied against the deal in Athens, with some throwing flares and rocks as riot police responded with tear gas.

“They had imagination, they took the risk, they were ready to sacrifice their own interests for the greater good,” European Council President Donald Tusk wrote on Twitter. “Zoran, Alexis — well done! Mission impossible accomplished.”

Before Friday’s vote in Athens, Macedonia already took care of its end of the bargain, ratifying the deal by narrowly meeting the two-thirds majority it requires for constitutional changes.

Zaev on Friday said the two countries had reached a “historic victory” that signified “eternal peace and progress” in the Balkans and in Europe.

Ancient Macedonia encompassed a broad area, and today a region of northern Greece is also known as Macedonia. Greece, before this vote, referred to its northern neighbor as the Former Yugoslav Republic of Macedonia, or FYROM. Some Greeks say Macedonians are making unjust claims over Greek territory or heritage.

In recent years, leaders in the country of Macedonia erected monuments that made claims to that ancient history. But Zaev tried to reverse course in a sign of goodwill. Last year, among similar moves, the government removed a reference to Alexander the Great from the name of its international airport.

Meanwhile, Tsipras continued to push for the deal, even as polls indicated that Greeks will soon hand the government to the conservative opposition in elections that must be held later this year. Analysts had said that if Macedonia or Greece had failed to ratify this agreement, it would be years before either country might find the political will to try again.

“I would like to address all Greeks who have their objections,” Tsipras said in remarks Friday. “Very soon they will see the benefits for the country from this historic step forward. Today North Macedonia was born. We welcome her.”

Elinda Labropoulou in Athens contributed to this report.