A total 69 lawmakers in Macedonia's 120-strong parliament voted to ratify the deal. All lawmakers from the conservative main opposition party, VMRO-DPMNE, abstained from the vote to protest the agreement, which they say cedes too much to Greece.
Parliament last month already ratified the deal, but conservative President Gjorge Ivanov refused to sign off on it, saying it is unconstitutional.
The agreement aims to resolve a decades-old dispute dating back to after Macedonia declared independence from Yugoslavia in 1991.
Greece argued the name "Macedonia" implied territorial aspirations on its own northern province of the same name, birthplace of the ancient warrior king Alexander the Great, and on ancient Greek heritage. Macedonia denies that.
Under Macedonia's constitution, Ivanov can no longer block it after Thursday's second ratification vote. However, the president might delay signing off on the deal, triggering a constitutional crisis and a showdown with leftwing Prime Minister Zoran Zaev, who has staked his political future on the deal.
The opposition party said later Thursday it had asked a senior prosecutor to file high treason charges against Zaev, the foreign minister, parliament speaker and all lawmakers who voted to ratify what it called an "act of capitulation" to Greece.
It was unclear how the prosecutor would respond.
Meanwhile, Foreign Minister Nikola Dimitrov strongly criticized Ivanov's stance during Thursday's debate, accusing him of trying to terrorize the country's population.
"The most important thing is that the deal does not jeopardize our independence," he said. "On the contrary, (the deal) strengths our independence by opening the doors to NATO and the European Union."
Full implementation of the agreement is subject to a referendum in Macedonia, a constitutional amendment — which Zaev currently lacks the majority to pass — and a parliamentary vote in Greece. In Athens, the issue has split the left-led governing coalition, and it is unclear whether the government will be able to pass it through parliament.
If everything goes as planned, Greece has promised to lift its objections to Macedonia starting accession talks with the EU and NATO.
Kostadin Kostadinov, a lawmaker from the governing Social Democrats, said Thursday that Ivanov has no option but to sign off on the agreement.
"No one is above the constitution and the laws," he said. "No one has the right to deprive Macedonia of its future."