Pahor had won about 53 percent of the vote, with 99.9 percent of the votes counted, according to the Election Commission, while his opponent, ex-comedian Marjan Šarec, had 47 percent. Turnout was about 42 percent, according to preliminary figures, the lowest for a presidential election since Slovenia became an independent country in 1991.
"I will be the president of all (Slovenians), I will connect people, build upon the things we have in common," Pahor told reporters after securing another five-year mandate. He had said that he would focus on cooperation, political stability and security.
Although the role of the president is mainly ceremonial, the president leads the army and also nominates several top officials, including the central bank governor. Most of his nominations have to be confirmed by parliament.
Pahor, 54, was forced into a second-round run-off after falling short of securing a majority in the first round last month.
Šarec, who is mayor of the northern town of Kamnik and represents a party that does not even have seats in parliament, said he was encouraged by the close result even though he lost. However, he refused to say whether his party would run in a general election expected in June next year.
"This is a very good result regardless of the final outcome ... and shows that the time for a generation change has arrived," he told TV Slovenia. "Tomorrow is a new day and then we will see how to proceed," he said when asked whether his party would run in the general election.
In the first round three weeks ago, Pahor won about 47 percent of the vote among nine candidates, with Šarec coming in second with almost 25 percent.
Pahor was a long-serving leader of the centre-left Social Democrats but ran for president both times as an independent candidate. He was Slovenian prime minister from 2008 to 2012, the run-up to the worst financial crisis in Slovenia's history.
In 2013, the euro zone member only narrowly managed to avoid an international bailout for its banks, burdened by a large amount of bad loans.
A former fashion model, Pahor is also known as "the king of the Instagram" for frequently posting photos on social media showing him in various sporting activities as well as his official duties.
Šarec, 39, campaigned arguing that a change of policy was needed to further improve the economy and lift Slovenians' living standards. He is supported by his own centre-left party, Lista Marjana Šarca, which has so far only been active at local level.