SKOPJE, Macedonia — Ending a debate that has raged for decades and kept the small Balkan nation of Macedonia outside the fold of the NATO alliance, Macedonian lawmakers on Friday night agreed to officially change the country’s name to the Republic of North Macedonia.

It was the penultimate step in what has been a long and tortuous journey for Macedonians and the government of Prime Minister Zoran Zaev, to finally, formally, end a dispute with Greece over the issue.

“We should raise our heads high, move past all the issues that divided our society,” Mr. Zaev told lawmakers before the vote on Friday. He called on them to look forward to a day when they could proudly find their nation’s flag waving in front of the NATO headquarters in Brussels.

Still, the secretary general of NATO, Jens Stoltenberg, said this was a historic moment and a victory for the Macedonian people.

“NATO strongly supports the full implementation of the agreement, which is an important contribution to a stable and prosperous region,” he said.

European leaders echoed his comments.

“Political leaders and citizens alike have shown their determination to seize this unique and historic opportunity in solving one of the oldest disputes in the region,” said Federica Mogherini, the high representative of the European Union, and Johannes Hahn, who leads efforts to expand the bloc, in a joint statement.

Image

Demonstrators holding Macedonian flags in November 2018, during a protest against renaming the country.CreditRobert Atanasovski/Agence France-Presse — Getty Images

“The E.U. strongly supports this agreement which sets an example of reconciliation for the region and Europe as a whole,” they added.

Indeed, at a moment when the bloc of nations is facing a raft of challenges, Friday night’s vote was viewed as a rare bit of good news and a triumph of diligent diplomacy. But there is still more work to be done.

Even before the vote in Skopje, a rift seemed to be growing over the issue between Prime Minister Alexis Tsipras of Greece and his right-wing coalition partner, Panos Kammenos.

Mr. Kammenos has threatened to leave the government, a move that could potentially force early elections.

While he has grown increasingly vocal, it is unclear if he will make good on his threat.

If Mr. Kammenos were to walk away, he would abandon his current job as defense minister with no guarantee that he would be able to prevent the name change from going through.

In a television interview on Wednesday, Mr. Tsipras said he was confident that Mr. Kammenos would continue to back the government, but he added that he would seek a vote of confidence in case his right-wing partner withdraws, saying he was certain he could secure the support needed to stay in power.

Mr. Tsipras also suggested that, should Mr. Kammenos withdraw, he would call snap elections rather than lead a minority government. He said that although the Greek Constitution would allow him to continue to rule with a minority government, “politically” there would be a problem.

In any case, he said, a snap election would take place after the Macedonia deal is ratified in the Greek Parliament and following the completion of some pending issues.

For Macedonians, Friday’s vote was the culmination of years of debate and was greeted by as much exhaustion as exhilaration.

Image

Prime Minister Alexis Tsipras of Greece in December. Greece must recognize Macedonia’s new name, the Republic of North Macedonia, before the nations’ decades-long dispute can end.CreditYannis Kolesidis/EPA, via Shutterstock

The dispute dates to 1991, when Macedonia declared independence during the breakup of the former Republic of Yugoslavia. Greece has long viewed the name as historically wrong — arguing that Macedonians were a Hellenistic people and therefore a name that could not be claimed by the Slavic people living in the country today — and a provocation.

Since NATO requires unanimity to accept a new member, Greece effectively kept Macedonia out of the security alliance.

Western diplomats have said they are concerned that Russia, which opposes NATO expansion, will step up its efforts to incite passions on the issue in Greece before the March deadline for a vote in Parliament. Even without outside interference, the issue can bring tens of thousands of Greeks into the streets in protest — as it has regularly done at each major milestone on the road to resolution.

The same was true in Macedonia.

But while nearly all Macedonians did not like being told they could not name their own nation, Mr. Zaev staked his government on the hope that a majority would recognize it was the only way to move forward.

As long as they called themselves Macedonia, Greece vowed to block the nation’s bid to join NATO, the first step on a path many hope will lead to membership in the European Union.

Despite the inconclusive result of a referendum, Mr. Zaev opted to continue with the implementation of the agreement and brought the measure before Parliament. It passed by the slimmest of margins, with a total of 81 members of Parliament — barely meeting the two-thirds majority needed — supporting the constitutional changes.

To convince enough lawmakers to support the name agreement, the government accepted and implemented a range of unpopular measures that even included amnesty for people who violently stormed Parliament in 2017.

Western leaders have been very supportive of the deal, hoping it will contribute to the stability of the historically volatile region. Chancellor Angela Merkel of Germany, who was visiting Athens in a show of support for Mr. Tsipras, praised his leadership on the issue.

“I am grateful to Alexis Tsipras, who took the initiative to find a solution along with Zoran Zaev regarding a very difficult issue,” she said at a news conference on Friday. “I am convinced that the solution will benefit Greece, North Macedonia, the stability in western Balkans and European Union.”

Niki Kitsantonis contributed reporting from Athens.

A version of this article appears in print on , on Page A8 of the New York edition with the headline: In Hopes of Mollifying Greece, Macedonia Votes to Change Its Name. Order Reprints | Today’s Paper | Subscribe