The prime ministers of Greece and Macedonia say they have agreed on "Republic of Northern Macedonia" as the new name for the Balkan country, ending a bitter 27-year dispute that had prevented the former Yugoslav republic from joining international institutions such as NATO.

Key points: The new name will be used both domestically and internationally

The new name will be used both domestically and internationally Macedonia will also amend its constitution as part of the deal

Macedonia will also amend its constitution as part of the deal The dispute over the "Macedonia" name had been a thorn in relations between the two countries at least since 1991

Greece's Alexis Tsipras and Macedonia's Zoran Zaev made the announcements shortly after speaking by phone.

The new name — which in Macedonian is Severna Makedonija — will be used both domestically and internationally, while Macedonia will also amend its constitution as part of the deal.

Greece had long demanded that Macedonia change or modify its name to avoid any claim to the territory and ancient heritage of Greece's northern region of Macedonia — birthplace of ancient warrior king Alexander the Great.

"There is no way back," Mr Zaev told a news conference as he explained the decision.

"We have been solving a two-and-a-half decade dispute … that has been drowning the country," he said, adding that the deal "will strengthen the Macedonian identity".

Mr Tsipras said the deal dictates "a clear distinction between Greek Macedonia and our northern neighbours".

"We have a deal," Mr Tsipras said.

"I'm happy because we have a good deal which covers all the preconditions set by the Greek side," he told Greek President Prokopis Pavlopoulos during a televised meeting.

"[The deal] puts an end to the irredentism which their current constitutional name implies."

He added that Macedonia "cannot and will not be able in the future to claim any connection with the ancient Greek civilisation of Macedonia".

Macedonia will no longer be able to claim Alexander the Great as part of the deal. ( By Christopher Bobyn )

The dispute over the "Macedonia" name had been a thorn in relations of the two countries at least since 1991, when Macedonia broke away from former Yugoslavia, declaring its independence under the name Republic of Macedonia.

Athens, which has a northern region also called Macedonia bordering on the ex-Yugoslav republic, objected to the name, demanding it be changed.

The row has stymied Macedonian attempts to join the European Union and the NATO military alliance in a region where the two organisations jostle for influence with Russia.

Mr Tsipras said the deal met the concerns of Greece that a revised name for Macedonia be a "compound" name with a geographical qualifier.

Athens and Skopje had been racing to agree the outline of a settlement before an EU summit in late June, though any accord would need to clear a referendum in Macedonia and win approval from politicians in both countries.

A NATO summit is scheduled for mid-July.

Sorry, this video has expired Protestors from both countries campaigned passionately about the name change (Photo: AP/Petros Giannakouris)

On the timeline of the deal, Mr Tsipras said that it would be first signed by the two countries' foreign ministers and then ratified by Macedonia's Parliament.

Greece will then back invitations for Macedonia to join NATO and start negotiations on joining the European Union.

However, Mr Tsipras said, this will be contingent on Macedonia completing the constitutional changes.

"In other words, if the constitutional amendment is not successfully completed, then the invitation to join NATO will be automatically rescinded and the accession talks with the European Union will not start," he said.

The deal was welcomed by EU officials, with European Council president Donald Tusk tweeting his "sincere congratulations" to Mr Tsipras and Mr Zaev.

"I am keeping my fingers crossed. Thanks to you, the impossible is becoming possible," he said.

AP/Reuters