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 Zaev's center-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)," 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.
Stoltenberg said in a tweet Friday that the agreement is "an important contribution to a stable and prosperous region."
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 toward 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.
Tsipras spoke with 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 Hristjan Mickoski accused Zaev's government of "blackmailing" lawmakers. Mickoski told reporters the constitutional changes were approved against the desires of the Macedonian people and described the vote as "an act of treason."
Tsipras has said he wants to bring the deal to Greece's parliament in coming weeks.
Associated Press writer Konstantin Testorides reported this story in Skopje and AP writer Nicholas Paphitis reported from Athens, Greece.
Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.