ROME — For months, a proposed deal to end three decades of rivalry between Greece and Macedonia has teetered on the brink of failure. The leaders spearheading the agreement in both countries have been accused of betrayal. They’ve faced street protests and opposition allegedly fomented by Russia. Days ago, after some defections from the ruling coalition, Greece’s prime minister barely survived a no-confidence vote.

But the agreement faces only one more hurdle, a vote in Greece’s Parliament that is expected this week. U.S. officials and political analysts are increasingly optimistic that one of Europe’s most enduring political fights is about to officially end, with Macedonia changing its name to the Republic of North Macedonia. Greece, in turn, would drop its long-standing opposition and allow its tiny neighbor to join NATO and the European Union.

A resolution of the name dispute would mark perhaps the most significant diplomatic step in the Balkans since the end of the Bosnian war, a development all the more surprising because it cuts against the continent’s trends. It would amount to a triumph for supporters of Europe, prevailing in the face of potent nationalist opposition while deepening integration at a time when Britain is on the verge of breaking away from the bloc.

But as the agreement looms, resistance has only mounted, particularly in Greece, where on Sunday opponents converged in Athens. Polls suggest that nearly 70 percent of Greeks are against the accord, and many in the country accuse Prime Minister Alexis Tsipras of overlooking national interests while pursuing a goal endorsed by U.S. and Western European policymakers.

The name deal “ is kind of a reminder of the liberal world order,” said Angelos Chryssogelos, a research fellow at Harvard University’s Weatherhead Center for International Affairs. “But moving forward, you can wonder if the price to be paid is deepening skepticism toward elites.”

On Sunday, with thousands gathered in front of the Greek Parliament, clashes broke out, and footage on social media appeared to show the use of tear gas. At least 25 police officers were injured and seven people arrested, the Associated Press reported.

Giorgos Tatsios, president of the Greek Federation of Macedonian Cultural Associations, said the rally was intended to push Tsipras to “respect the will of the people” and hold a referendum.

“The vast majority of Greek people do not want this agreement,” he said.

The debate over the name of a country born after the breakup of Yugoslavia may seem obscure, but it has become a touchstone of national identity in Macedonia and Greece. Historic Macedonia encompassed a broad region that is part of several nations, including northern Greece and the country with the disputed name. But Greeks deny that the majority-Slavic population of their northern neighbor has a rightful claim to Macedonian heritage.

The debate has raged for decades over everything from museums to airports named for Alexander the Great. Under a previous government, Macedonia erected hundreds of hastily made monuments and statues to press its claim to a proud history. Greeks felt antagonized.

“We cannot simply hand over our name, our identity, to the Slavs,” said Georgia Tzeni, 32, a homemaker from northern Greece who said the Greek government is “giving away what generations have fought for. They are not listening to the people.”

But beyond the Balkans, the deal has widespread support from the West, and for months, U.S. and European officials have shuttled into Athens and Skopje to push the accord along. Policymakers see the Balkans as a battleground in the struggle with Russia for influence and argue that Macedonia’s E.U. membership would stabilize the region and perhaps set a precedent for compromise that can ease other disputes.

A. Wess Mitchell, the assistant secretary of state for European affairs, said the United States strongly supports the Prespa agreement, as the deal is known, and predicted it would be ratified by the Greek Parliament.

“I’m very confident we’re on a good path,” he said. “It could possibly be the greatest achievement in the Balkans, the greatest contribution to stability, since Dayton,” the 1995 peace agreement for Bosnia.

Russia has been accused of cultivating opposition to the deal. In September, then-Defense Secretary Jim Mattis said there was “no doubt” that Russia was funding an influence campaign against the pact. Greece expelled two Russian diplomats and barred two others for alleged bribery attempts to fan resistance.

In a news conference last week, Russian Foreign Minister Sergey Lavrov said his country supported dialogue between Greece and Macedonia but had questions about the legitimacy of the process, including whether it has been “conditioned by the U.S. desire to drive all Balkan countries into NATO as soon as possible and stop any Russian influence in that region.”

Macedonia has been a member of the United Nations for more than two decades, but with the alphabet-soup name of FYROM (the Former Yugoslav Republic of Macedonia) that was, part of an earlier compromise with Greece.

This time, the path to a finalized agreement has run through the parliaments in Macedonia and Greece. The countries’ leaders reached the deal in principle in June, but it still needed ratification. Macedonia’s parliament approved it this month, narrowly garnering the two-thirds majority necessary for constitutional changes.

That has shifted attention to Greece, where months of name-related drama have already led to the resignation of Tsipras’s foreign and defense ministers. Tsipras’s left-wing party, Syriza, holds 145 seats in the 300-seat chamber. Analysts say the prime minister appears to have cobbled enough support from independent members and small parties to ratify the deal.

But if it falls through, it could be years before Macedonia and Greece have a similar opportunity.

In Macedonia, the prime minister is Zoran Zaev, a left-leaning economist who shows little of the nationalism of his predecessors.

“He was never part of that old establishment,” said Stevo Pendarovski, Macedonia’s NATO coordinator. “He was approaching all of these problems with a cold mind. There’s no other way for such a small country to prosper if we are not integrated.”

Meanwhile, Tsipras has expended political capital to push the deal in what will probably be his last months in office. Polls indicate his party will lose an election that must take place this year. Tsipras took office in 2015 as an economic populist, promising to push back against Europe and rewrite the terms of its bailout. But the gambit failed, and he has since remade himself as a more conventional center-left leader, drawing close, most notably, to German Chancellor Angela Merkel. Greeks say Tsipras views the name deal as a legacy project.

“Maybe his calculus was: I will pay a certain price, but that will establish my image as a dominant figure in the center-left and also a statesman outside of Greece,” said Thanos Dokos, director general of the Eliamep think tank in Athens. “Which I think is accurate as of now. He has benefited considerably outside of Greece.”

Elinda Labropoulou in Athens and Carol Morello in Washington contributed to this report.