"We wholeheartedly congratulate Prime Ministers Alexis Tsipras and Zoran Zaev for their determination and leadership in reaching this historic agreement", said EU foreign affairs chief Federica Mogherini and European Commissioner for Enlargement Negotiations Johannes Hahn in a joint statement.
The long-running dispute has centred on Greece's objection to Macedonia's name, which has prompted it to block its neighbour from joining North Atlantic Treaty Organisation and the European Union until it is changed.
"There is no way back", Zaev said in a news conference.
It is now known formally at the United Nations under the interim name "Former Yugoslav Republic of Macedonia".
Thankfully, it sounds like Greece and Macedonia have finally reached a resolve, thanks to the new name of the Republic of North Macedonia - or "Severna Makedonija" in Macedonian.
But Macedonia feared that a name change could have a negative impact on the national identity of its people, the majority of whom simply call themselves "Macedonians".
In a televised address, Tsipras said the 140 countries which had recognized the Balkan state simply as Macedonia would now recognize it as Republic of North Macedonia.
Zaev said the deal would be signed this weekend, and a voter referendum would be held in the fall.
Many Greeks felt their northern neighbor was trying to hijack Greece's ancient cultural heritage.
Both governments have faced criticism ahead of the compromise and on Tuesday Macedonia's President Gjorge Ivanov signalled his concern.
"In other words, if the constitutional amendment is not successfully completed, then the invitation to join North Atlantic Treaty Organisation will be automatically rescinded and the accession talks with the European Union will not start", he said.
Greece also demanded that Macedonia drops from its flag the rayed sun of Vergina, which it claimed was an ancient Greek symbol, as well as certain articles from its constitution.
'I am keeping my fingers crossed, ' he said. The dispute poisoned relations between the two neighbours, and the United Nations appointed a special envoy to mediate.
In Athens, Greek Prime Minister Alexis Tsipras called the deal "historic".
European Union foreign affairs chief Federica Mogherini and commissioner Johannes Hahn issued a joint statement congratulating the two prime ministers "in reaching this historic agreement between their countries, which contributes to the transformation of the entire region of South-East Europe".
In Skopje, the opposition party VMRO-DPMNE, said Macedonian Prime Minister Zoran Zaev had informed party leader Hristijan Mickoski that he had "achieved a solution with Greece".