“It’s really telling that a candidate like Pahor, with so much experience, skill and popularity, had such a challenger in Sarec, who comes from nowhere and appears to have little to offer,” said Tanja Staric, a veteran political reporter who is now the news editor of Slovenia’s public broadcasting network.

Ahead of the runoff, Mr. Sarec had narrowed Mr. Pahor’s lead in the opinion polls, an indication that Slovene 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.

Nearly 42 percent of 1.7 million eligible voters — 715,096 — cast their ballots on Sunday, just under the turnout after the first round, on Oct. 22, when 43 percent of eligible voters in Slovenia cast ballots.

The presidential election is considered a dress rehearsal for next year’s vote for Parliament. The fight for control of the government 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.

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.

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. He had served as the country’s prime minister and the president of its Parliament before being elected president in 2012.

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 had managed, she said, to appeal to “ordinary people, the average Joe, who feels left behind in the global economy.”