Sarec conceded defeat and congratulated Pahor, but said that his success as a relative political newcomer showed that Slovenian citizens wanted change.
"I'm proud to have had a possibility to run against premiere league," Sarec said at his headquarters in Kanik. "My result is good, it speaks for itself."
Pahor is only the second Slovenian president to win a second term in office since the country gained independence from the former Yugoslavia in 1991. The country of 2 million people in Central Europe is the birthplace of US first lady Melania Trump and is known for its Alpine mountains and lake.
Pahor, a former model like the US first lady, has held a number of public posts and was Slovenia's prime minister before he was first elected president in 2012. He has sought to portray himself as a uniter of all Slovenians. Critics say he simply avoids taking stands on important issues.
Slovenia's presidency carries no executive powers, but the office-holder proposes a prime minister and his or her opinion on important issues holds weight. Pahor and Sarec, while both centrists, clashed on issues such as the privatization of Slovenia's biggest bank and the composition of the country's anti-corruption body.
Key topics facing Slovenia include the economy, a border dispute with Croatia and the future of the European Union, which Slovenia joined in 2004.
After voting Sunday, Pahor complained that he has been falsely viewed as a populist - which he says he is not - while Sarec was trying to assume the role of a "statesman." Pahor suggested that the "change of roles" cost him public support.
Sarec, for his part, expressed confidence that he could win.
"I wouldn't have run for the position if I hadn't thought I could be elected," he said.
Sarec was a well-known satirical comedian before entering politics in 2010 to run for mayor.
More about: #Slovenia