Greek MPs have ratified a landmark accord allowing the country’s tiny northern neighbour Macedonia to change its name, in a momentous development for the stability of a region all too often riven by wars, nationalist populism and memories of blood-soaked mutual suspicion.

After one of the most contentious votes in Greek history, Nikos Voutsis, the president of Athens’ 300-seat parliament, announced the result at 3.35pm local time (1335 GMT). In all, 153 MPs declared support for a deal that not only renames the strategic Balkan state North Macedonia, but ends an abstruse diplomatic dispute that has raged for almost 30 years.

The result paves the way for the former Yugoslav republic to join Nato and eventually the EU – alliances hitherto blocked by Athens.

Rushing to congratulate his Greek counterpart, Alexis Tsipras, the Macedonian prime minister, Zoran Zaev, tweeted: “Together with our peoples we reached a historical victory. Long Live the Prespa Agreement! For eternal peace and progress of the Balkans and in Europe.”

Tsipras called it “a historic day for Greece that ends an issue that was a burden for our foreign policy”.

The vote – two weeks after MPs in Skopje ratified the constitutional amendments needed to change their country’s nomenclature – followed five days of acrimonious debate in Greece, where nationalist sentiment had reached fever pitch.

Facebook Twitter Pinterest A priest waves a Greek flag as he protests against the vote outside the parliament building in Athens. Photograph: Louisa Gouliamaki/AFP/Getty Images

In and outside the parliament, opponents had deplored the pact as an act of unprecedented betrayal. Iron- and crowbar-wielding protesters attempted to storm the building during a demonstration that drew tens of thousands last week.

MPs were labelled traitors and several in Tsipras’s Syriza party received death threats by text message. Surveys on the eve of the vote showed more than 60% of Greeks opposed the accord. Few believed the deal – struck between the two nations’ leftist governments last year – would get this far.

Dimitris Orfanoudakis, a farmer who had travelled from Crete with his flag-draped teenage son, Giorgos, to join the protests, summed up the mood: “It is treason and it has to stop. We are the only people in the world who have to defend our borders from our own politicians because what they are doing is a national crime. Macedonia is one, and it is Greek.”

No other state – with the exception of Austria after the first world war in 1919 – has been forced to change its name in modern times. For Macedonia, inhabited predominantly by Slavs but also ethnic Albanians, the dispute had become a matter of identity that, at times, bordered on existential crisis. For Greece, where most of the geographical area of Macedonia was incorporated after the Balkan war in 1912-13, sensitivity to issues of cultural heritage also run deep.

When landlocked Macedonia declared independence with the dissolution of Yugoslavia in 1991, Athens hit back, arguing that monopolisation of the name would unleash the genie of territorial ambition against Greek Macedonia, which includes the port city of Salonika. Fears had been fuelled by Skopje appropriating figures and symbols from ancient Greek history, including the erection of a gargantuan statue with an uncanny likeness to Alexander the Great – the most famous Macedonian of all – in the republic’s central square.

“Greeks have vivid memories of Macedonia being fought over four times in the past century alone,” said Angelos Syrigos, a professor of law and foreign policy at Panteion University in Athens. “This agreement would have been a fair compromise if the new name applied to everything and by that I mean language, citizenship and nationality. Right now we have something in between. If our neighbours are known as ‘Macedonians’ who speak the ‘Macedonian’ language, that in the future could be the basis for territorial claims.”

For Tsipras and Zaev, adding the geographical qualifier of “north” to the state’s new name was an honourable compromise that, once accepted, could normalise ties in the otherwise volatile western Balkans.

Facebook Twitter Pinterest A member of the Union of Centrists party holds a banner reading ‘Don’t blame Democracy’ during the vote in parliament. Photograph: Alexandros Beltes/EPA

Internationally, both leaders have been praised for their courage in defying nationalist sentiment on the ground. But what European officials see as “a unique and historic opportunity” to settle a dispute that has defied solution for decades, has tested the two politically.

“Tsipras submitted to pressure from the Europeans, especially [Angela] Merkel,” said Panos Kammenos, who heads the populist rightwing Independent Greeks party, the ruling leftists’ junior partner in government until it pulled out in protest over the accord.

Responding to the vote, the main opposition leader, Kyriakos Mitsotakis, described the deal as a “national retreat” that marked “a difficult and distressing” day for the EU member state. Mitsotakis’s New Democracy party has a double-digit lead in polls ahead of general elections later this year. Far too many concessions had been made, he said, adding that once in government he would veto any hopes of Skopje joining the EU.

Under the agreement Macedonia must notify the United Nations, where it is known as the Former Yugoslav Republic of Macedonia, or Fyrom, before it officially changes its name – a monumental task that requires thousands of documents being changed both at home and abroad.

On both sides there is recognition that the accord’s implementation will be far from simple. Committees have been created to help cement the friendship that has eluded the two nations for the past 27 years, including supervision of history teaching in schools.

“A new chapter begins of building the confidence lost between the two but it is not going to be easy,” insisted Prof Dimitris Christopoulos, a political scientist at Panteion University. “State-to-state relations have poisoned people-to-people relations.”

On the ground many agree. In a country that has become increasingly polarised as general elections loom, opponents are girding for battle.

“We will take to the streets as they have done in France,” said Orfanoudakis, the Cretan farmer. “There’s going to be chaos. After eight years of financial crisis, of having foreigners pauperise us, they are not going to take our Macedonia away, too.”