Leading up to the runoff, Mr. Sarec, 39, had narrowed Mr. Pahor’s lead in the opinion polls, an indication that Slovenian voters were in sync with those across Europe, where candidates campaigning from the fringe of traditional political parties and the governing elites have steadily gained support.
The presidential election is, however, considered a dress rehearsal for next year’s vote for Parliament.
While there is a populist tilt in Slovenia, the shift is nowhere near the seismic changes in Britain, where voters last year backed leaving the European Union; in Germany, where the Alternative for Germany became the first far-right party to enter Parliament in decades after elections in October; or in Austria, where the People’s Party emerged in October as the strongest political force in the country, setting the course for a rightward shift.
Both candidates in Slovenia have run as independents, but Mr. Pahor is deeply entrenched in the traditional party system of the left that has ridden the waves of European social democracy since the collapse of Communism.
Mr. Sarec, who was elected mayor of Kamnik in 2010, is better known for impersonating politicians on a satirical radio program than for being one himself, Ms. Staric said. In the past three weeks, however, he has managed, she said, to appeal to “ordinary people, the average Joe, who feels left behind in the global economy.”
The collapse of the health care system, unemployment among the youth and the economic recovery were among the major issues for voters. While Slovenians say they do not expect the president to solve their problems, they say they hope that the elected candidate will provide moral guidance to the new Parliament next year.
Slovenia is the wealthiest and most socially progressive of the states that have emerged from the collapse of Yugoslavia. In 2004, it was also the first to join the European Union and NATO as the rest the region still reeled from devastating wars and the grip of nationalist rulers.
Yet Slovenia, a country the size of New Jersey, has struggled to find its place in the European Union, with its leaders refusing to partner openly with other Central European countries like Hungary and Poland, which are striving to be one of the 28-member bloc’s core decision-makers, like Germany and France.
During the campaign, Mr. Pahor, who led an American-style campaign using social media to lure voters, insisted that Slovenia belonged to that group of powerful countries. And he frequently dropped the names of Chancellor Angela Merkel of Germany and Jean-Claude Juncker, president of the European Commission, as his “friends.”
While Mr. Sarec has emphasized his pro-European Union stance, he has also promised to address Slovenians’ concerns about what they see as the European Union’s failure to hold a unified position on immigration or to find solutions to economic malaise in the eurozone.
Slovenia has yet to recover from a downturn in 2009; its economy has shrunk by 8 percent.
During the migration crisis in 2015, Slovenia was a front-line country, with tens of thousands of migrants crossing on their way to seek asylum in Germany and Sweden. Last year, Slovenia’s government was instrumental in closing the so-called Balkan route for migrants, working with Austria to its north and fencing off its border with Croatia to the south to stem the flow.
The presidency in Slovenia’s highest elected office, but it holds no executive powers. The winner will be the commander in chief of the armed forces and will have the power to dissolve Parliament and call early elections.
The fight for control of the government next year will pit the right-wing nationalist Janez Jansa, the former prime minister and the current opposition leader, against Dejan Zidan and his left-of-center social democrats.