After decades of claims, counterclaims and, at times, ugly politics, Athens and Skopje have resolved one of Europe's most intractable conflicts.

A lengthy, stormy debate in Greece's 300-seat parliament concluded on Friday with a majority of 153 legislators voting in favour of a deal seeking to end the two neighbours' long-running dispute by renaming the Former Yugoslav Republic of Macedonia as the Republic of North Macedonia. A total of 146 MPs voted against the deal and one abstained.

"Today is a historic day. Greece protects an important part of its history, the heritage of ancient Greek Macedonia," said Greek Prime Minister Alexis Tsipras on Twitter at the end of a bruising process which saw his ruling coalition ally quit earlier this month.

Macedonian Prime Minister Zoran Zaev congratulated Tsipras and hailed the outcome as a "historical victory".

Congratulations my friend @tsipras_eu, 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! pic.twitter.com/f9aIpMa4Xz — Зоран Заев (@Zoran_Zaev) January 25, 2019

According to the contentious Prespes Agreement, signed in June last year, the small Balkan country will now be internationally recognised as North Macedonia in exchange for Greece unblocking its path towards NATO and European Union membership. Its language will be recognised as "Macedonian" and its citizens as "Macedonian/Citizen of the Republic of North Macedonia".

The vote in Athens, which came nearly two weeks after MPs in Skopje narrowly approved the name change, settles the countries' 27-year dispute.

Societies in both countries, however, remain polarised.

In Athens, thousands of people waving flags and chanting "traitors" gathered outside the Greek parliament building on Thursday evening to protest against the agreement.

Similar protests were held in other parts of the country, mostly in northern towns where opposition to the deal is stronger, polls showing six in 10 Greeks rejecting the agreement.

Athens has long opposed the use of the name Macedonia for its neighbour, which declared independence in 1991 following the break-up of the former Yugoslavia, saying it implied a territorial claim over the Greek province with the same name as well as an appropriation of Greece's cultural heritage. Skopje has denied the allegations.

"Certain Greeks oppose the deal because they believe that the term Macedonia historically belongs to the Greeks. Therefore the use of 'Macedonia' by our northern neighbour it's like an historical theft committed against 'Greekness'," Dimitris Christopoulos, professor of political science at Panteion University in Athens, said.

In Skopje, opponents of the deal have also taken to the streets in recent months.

Trajko Slaveski, a former minister of finance and current member of the opposition VMRO-DPMNE party, described the agreement as a defeat for his country.

"The deal represents a sheer capitulation under the irresponsible demands of a neighbouring country, both a NATO and EU member, and as such could not be supported," Slaveski told Al Jazeera.

For Slaveski, it's not only a matter of legitimacy but also about heritage and identity.

"The name of the country, and, moreover, the identity, culture, and history of its people has been changed under immense pressure, with numerous breaches of our constitution and respectful laws. This undermines the very foundations of our country and society, with grave consequences for our future," he argued.

Still, others believe the agreement holds positive implications for the two countries, both at the regional and European level.

"The deal shows that the carrots and sticks of the EU process work and that the EU can function as a peace project, while it reaffirms the presence of NATO and the EU in the region," Nikos Skoutaris, senior lecturer in European Law at the University of East Anglia, said.

The deal will also enable greater cooperation in many areas, including in dealing with the refugee crisis and fostering better economic ties, according to Gjorgji Filipov, a diplomat in Skopje.

"Macedonia and Greek are winning and losing something, but finally is for the good of both sides," he said.