President Gjorge Ivanov said the agreement, which would rename Macedonia as the Republic of North Macedonia, gave too many concessions to Greece.
"Such a harmful agreement, which is unique in the history of mankind, is shameful and unacceptable for me," Ivanov said in a TV address. "It violates the Constitution (and) the laws ... I will not legalize political illegal agreements."
The deal reached by the prime ministers of the two countries is expected to be signed by their foreign ministers this weekend. After that, Macedonia's parliament would vote on it, and if it is approved, Ivanov's signature would be needed.
If the president refuses to sign, the deal would return to parliament for another vote. Ivanov would have to sign off on the agreement if it is passed a second time.
The name dispute, which has prevented Macedonia from joining international institutions such as NATO, has roused strong nationalist sentiments and poisoned the two countries' relations since the Balkan country declared independence from Yugoslavia in 1991.
Greece argues that the term "Macedonia" implies a claim on the territory and ancient heritage of its own northern province of the same name - the birthplace of ancient warrior king Alexander the Great.
European Council President Donald Tusk and NATO Secretary General Jens Stoltenberg issued a statement Wednesday welcoming the deal and acknowledging that domestic politics still could scuttle it.
"We hope that this unique opportunity to relaunch the wider Western Balkan region's European and Euro-Atlantic integration will not be wasted," the statement said. "This agreement sets an example for others on how to consolidate peace and stability across the region."
The agreement reached by Prime Minister Alexis Tsipras and Macedonian Prime Minister Zoran Zaev has strong dissenters, with opponents staging large protests on both sides of the border. The issue threatened to split Greece's governing coalition, and provoked a rift between Zaev and his president.
"Everything that is sacred to Macedonia is being trampled underfoot, and the unborn are deprived of the right and pride to be Macedonians," Ivanov said in his address.
Up to 1,500 people held a peaceful protest against the deal outside Macedonia's parliament in Skopje late Wednesday, chanting "Traitors" and blowing whistles.
Greek opponents of the deal are planning a rally in Athens on Friday. Hardliners on both sides are arguing that their prime ministers conceded too much to reach the deal. In Macedonia, Zaev has said he will put the deal to a referendum in the fall.
Zaev, accompanied by Foreign Minister Nikola Dimitrov, visited Ivanov Wednesday to brief him on the deal. But Ivanov refused to discuss the issue.
"President Ivanov ... left the meeting, refusing to talk about the achievements of this historical agreement," the government said in a statement.
"I think Prime Minister Zaev's most difficult task will be to actually explain the deal, to build political consensus for the implementation and, of course, the upcoming referendum," said political analyst Petar Arsovski.
Greece's Tsipras also faces opposition at home.
Defense Minister Panos Kammenos, whose right-wing Independent Greeks party is the coalition partner in Tsipras' government, said he would oppose the agreement in a parliamentary vote. This would leave the left-wing prime minister dependent on support from political opponents to ratify the deal in parliament.
But Tsipras said he expects Greek lawmakers to easily approve the agreement.
"(It) won't have trouble in passing," he said during a TV interview. "It will be approved with a big majority."
He also ruled out a Greek referendum on the name-change.
Kyriakos Mitsotakis, the head of New Democracy, Greece's main opposition party, described the agreement as "deeply problematic" and called on Greece's president to intervene so the deal can be debated in parliament before it is signed, instead of after.
On the streets of both capitals, reactions were mixed.
"We lost the country, this is a disaster," 45-year-old lawyer Mila Ivanovska said in Skopje, the Macedonian capital, and began to cry.
Greek opponents were equally angry.
"You, Slavs from Skopje through the centuries, you have never been true Macedonians," said Athenian resident Konstandinos Goutras.
But for others, the deal marks a welcome end to a protracted dispute.
"North Macedonia is acceptable for me," said Svetlana Jancevska, a 55-year-old music teacher in Skopje, adding that it will "not damage my identity as Macedonian. The language remains Macedonian and that makes me happy. It was high time for the problem to be solved."
The dispute was deadlocked for years but hope for a resolution was rekindled after Zaev became Macedonia's prime minister last year, replacing conservative Nikola Gruevski who had served as prime minister for a decade.
Opponents in Greece object to any use of the term "Macedonia" in their northern neighbor's name, fearing territorial claims and seeing the use of the name as a usurping of Greece's ancient heritage. Opponents in Macedonia see any modification of the country's name as a threat to their national identity.
According to what has been released, the citizens of the newly named country will be called "Macedonian/citizen of the Republic of North Macedonia." The deal includes provisions for labels to be placed on statues erected in Macedonia depicting the likeness of Alexander the Great which make clear they refer to ancient Greek times.
After it's ratified by Macedonia, Greece will then back invitations for Macedonia to join NATO and start negotiations on joining the EU. However, Tsipras said, this will be contingent on Macedonia completing the constitutional changes.
Mironski reported from Skopje, Macedonia. Florent Bajrami in Skopje, Raphael Kominis and Nicholas Paphitis in Athens, Greece, contributed to this report.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.