The ruling Social Democrats' candidate, Stevo Pendarovski, captured 51.75 percent of the vote, with nearly all the ballots counted according to the state electoral commission.
His rival Gordana Siljanovska-Davkova, a law professor backed by the right-wing opposition, was around 60,000 votes behind with 44.65 percent, the commission website said.
"I will be a president for all of the citizens, no matter who they voted for," Pendarovski told a crowd chanting "Stevo! Stevo!" at the ruling party's headquarters, where music and dance erupted after his win.
A political science professor who is coordinating the country's efforts to join NATO, Pendarovski has been championing the government's name deal with Greece.
The accord, which was finalised this year and added "North" to Macedonia, ended a decades-old identity dispute with Athens that was blocking Skopje's EU and NATO ambitions.
But it angered segments of the public who felt the move sacrificed the Balkan state's identity.
The opposition-backed candidate, Siljanovska-Davkova, was also critical of the deal.
In a speech after the election she conceded the numbers were "pointing to a defeat".
Pendarovski's win helps steady the course of Prime Minister Zoran Zaev's government, who is hoping that the name change will be rewarded with the opening of EU accession talks in June.
The government also breathed a sigh of relief Sunday to see turnout pass the 40 percent threshold required to make the poll valid.
According to the electoral commission, around 46 percent of a 1.8 million electorate cast ballots.
While the presidency is a largely ceremonial role, the office can exercise some veto powers.
The outgoing president, opposition-backed Gjorge Ivanov, has been refusing to sign bills in protest at the name change finalised earlier this year.
Pendarovki's win is a "firm forward for the European integrations," said Macedonia-based analyst Albert Musliu .
But he said it should also give the government a push to "finally take seriously their own promises" on reforms, such as cleaning-up the bureaucracy and cracking down on corruption.
Earlier on Sunday, after casting his own ballot, Pendarovski said he expected voters to rally around his call for a "unified North Macedonia, with all ethnic communities being equal to each other".
The country is home a large ethnic Albanian population, who form up to a quarter of the population.
Pendarovski performed well in Albanian districts Sunday after their candidate had fallen out of the race in the first round of voting last month.
But despite calls for unification, the close race captured a deep fault line in the Balkan country.
There is also a wide swathe of society that has been snubbing the polls, reflecting disillusionment with a governing class that has failed to turn around a stagnant economy.
Low wages, high unemployment and widespread corruption have been gnawing away at public faith in politics for years.
Huge numbers of young people have left the country in recent years, sowing concern of a "brain drain" crisis.