Macedonia fulfilled its part of a historic deal on Friday that will pave its way to NATO membership and normalise relations with neighbouring Greece, after lawmakers approved constitutional changes to rename the country North Macedonia.

The move was hailed by NATO and the European Union, which had lobbied heavily for Macedonia to back the agreement despite strong criticism from the country's main opposition party, and by Greece's prime minister who has invested heavily in the deal.

All 81 Macedonian lawmakers present for the parliamentary vote backed the constitutional amendments. The remaining 39 opposition lawmakers in the 120-seat house stayed away in protest.

Prime Minister Zoran Zaev told lawmakers the deal was a "tough" but necessary decision for his country.

The vote followed intense negotiations between Mr Zaev's centre-left coalition and some opposition lawmakers, who had initially agreed to back the agreement but raised last-minute objections.

"A better deal could not be reached, and without an agreement with Greece there will be no NATO and European Union (membership)," Mr Zaev said.

The agreement on changing the name comes after a 27-year dispute with Greece, which complained that this small, landlocked country calling itself Macedonia implied claims on Greece's own territory and cultural heritage. Macedonian leaders denied that.

The deal encountered strong opposition on both sides of the border, with critics on each side saying it offered too many concessions to the other side.

NATO leader Jens Stoltenberg said the alliance strongly supports the full implementation of the agreement, under which Greece will lift its objections to Macedonia joining NATO and the EU.

Mr Stoltenberg said in a tweet on Friday that the agreement is "an important contribution to a stable and prosperous region."

Macedonian government: Thousands gather to demand tough stance in name dispute

EU foreign policy chief Federica Mogherini said the bloc strongly supports the deal and "remains firmly committed to continue to fully support and accompany (Macedonia) towards its common strategic goal of EU integration."

Western governments see Macedonia's NATO accession as a key step towards limiting Russian influence in the region.

For the agreement to come into effect, Greece's parliament must now convene in coming weeks to ratify it — a tricky task for Greek Prime Minister Alexis Tsipras who faces strong opposition to the agreement from his junior coalition partner.

Mr Tsipras spoke with Mr Zaev on Friday to congratulate him after the vote, the Greek prime minister's office said.

Hundreds of Macedonian opposition supporters protested peacefully in front of parliament for a third day, demanding early elections and the dissolution of parliament. They greeted the vote result with cries of "traitors."

Conservative opposition leader Hristijan Mickoski accused Mr Zaev's government of "blackmailing" lawmakers. Mr Mickoski told reporters the constitutional changes were approved against the desires of the Macedonian people and described the vote as "an act of treason."

Mr Tsipras has said he wants to bring the deal to Greece's parliament in coming weeks.