ATHENS, Greece — Greek lawmakers ratified an agreement Friday to end a nearly three decade-long dispute over neighboring Macedonia’s name, in a landmark vote that will see the small country renamed North Macedonia and clear its path to NATO membership.

The deal passed with 153 votes in the 300-member parliament, two more than needed. It has faced fierce opposition in both countries, and recently cost Prime Minister Alexis Tsipras his parliamentary majority after a small right-wing party quit the governing coalition in protest. It passed with the support of independent lawmakers.

Tsipras' left-wing Syriza party holds 145 seats in parliament, six short of a majority.

"Today is a historic day," Tsipras said. "Greece is safeguarding an important part of its history, its heritage of ancient Greek Macedonia. Today we are writing a new page for the Balkans."

Under the deal, Macedonia changes its name to North Macedonia, and Greece drops its objections to the country joining NATO and eventually the European Union.

With Greek parliament's ratification, the agreement is almost complete although some procedural steps remain, including Greece signing its northern neighbor's NATO accession protocol.

Want in on NATO? That can be easier said than done.

"Congratulations my friend Alexi Tsipras, together with our peoples we reached a historical victory," Macedonian Prime Minister Zoran Zaev tweeted.

The Macedonian government issued a statement congratulating the people of both countries. "The Balkans, Europe and the world have received a new model for building friendships and cooperation between nations and states," it said.

The ratification was quickly welcomed by both NATO and the EU.

Friday's vote was "an important contribution to the stability and prosperity of the whole region," NATO Secretary-General Jens Stoltenberg tweeted. "I look forward to the future Republic of North Macedonia joining NATO."

The ratification came after three days of acrimonious parliamentary debate and numerous street protests, some of which turned violent. A rally last Sunday saw tens of thousands of people gather outside parliament, with clashes erupting between groups of demonstrators and riot police.

Holding a flag with the Star of Vergina, the emblem of the ancient Greek kingdom of Macedonia and Alexander the Great, an opponent of the Prespa Agreement attends a rally on Jan. 25, 2019. (Giannis Papanikos/AP)
Holding a flag with the Star of Vergina, the emblem of the ancient Greek kingdom of Macedonia and Alexander the Great, an opponent of the Prespa Agreement attends a rally on Jan. 25, 2019. (Giannis Papanikos/AP)

Torrential rain and driving wind kept many protesters away on the final day of the debate. Scores of demonstrators who braved the weather conditions outside parliament chanted "traitors" as lawmakers voted inside.

Top EU officials said the ratification has "written a new page of our common EU future."

European Commission President Jean-Claude Juncker, the EU’s top diplomat and the senior official supervising the bloc’s enlargement, said it “took political courage, leadership and responsibility on all sides to resolve one of the most entrenched disputes in the region.”

Greece has long argued use of the term Macedonia implied territorial claims on its own northern province of the same name. The issue has been a contentious one for decades, stymieing repeated rounds of U.N.-mediated negotiations and whipping up nationalist and patriotic sentiment in both countries.

Opposition has been particularly fierce in the northern Greek region of Macedonia, which borders the republic that claimed the same name after declaring independence from the former Yugoslavia in 1991. Critics claimed the deal signs away their identity and a cultural heritage dating back to Alexander the Great more than 2,300 years ago.

More than 150 people have been detained for questioning since Thursday following violence at demonstrations against the deal in Athens and two towns in northern Greece. Most were released without charge.

At least two lawmakers from the governing Syriza party have said their homes were targeted by violent demonstrators, while another was targeted in a firebombing that caused no injuries. Greece’s tourism minister, an independent conservative who supports the government, said she had received multiple death threats.

Britain also welcomed the ratification, describing it as a "historic moment bringing a decades-old dispute close to an end."

"Today's vote paves the way to the full implementation of the agreement, which has the full support of the U.K.," Foreign Secretary Jeremy Hunt said in a statement released by his office. "Both countries have demonstrated great courage and the will to work together to affect real change."

Derek Gatopoulos in Athens; Konstantin Testorides in Skopje, Macedonia; Lorne Cook in Brussels; and Danica Kirka in London contributed to this report.