SKOPJE, North Macedonia — In a presidential runoff, voters in North Macedonia on Sunday elected a government-backed candidate who plans to bring the country into NATO under its new name over a rival who had vowed to challenge the name change if elected.

With nearly all ballots counted, Stevo Pendarovski, a joint candidate of the governing Social Democrats and 30 smaller parties, had about 52 percent of the vote, compared with about 45 percent for his opponent, Gordana Siljanovska Davkova.

Mr. Pendarovski, 56, has defended a recent deal with Greece to make the change, enabling what was the Republic of Macedonia, one of Europe’s poorest countries, to move forward with membership in NATO and possibly in the European Union.

“The agreement is a good agreement, a necessary agreement,” Mr. Pendarovski said in an interview at the governing party’s headquarters in Skopje, just before he declared victory.