Known to many as "Barbie," Borut Pahor has apparently been elected the president of Instagram in Slovenia.

He boasts more than 42,000 followers in a nation of 2 million inhabitants.

But as polls closed on Sunday, the longtime Social Democrat hadn't quite managed to secure the presidency for a second time. With 99 percent of the vote counted, according to the State Election Commission, Pahor had won 47.1 percent of the vote, meaning he will face a runoff next month against challenger Marjan Sarec, mayor of the northern town of Kamnik, who took 25 percent. Turnout was 43.5 percent.

"In the second round anything is possible, although Pahor is a big favorite," Peter Jancic, the editor of political website Spletni Casopis told Reuters news agency.

First elected president in 2012, Pahor has held almost all of Slovenia's most important positions. His popularity mostly derives from the fact that Slovenes have nothing to complain about, except, perhaps, their border dispute with Croatia.

Slovenia's economic development is solid. The country's infrastructure has undergone extensive modernization: it is ranked second in the European Union in digital progress, major roadwork has been completed, and large-scale rail network projects have been launched.

Bordered by Italy, Austria, Hungary and Croatia, Slovenia has always performed well economically; it had been the most developed state in Yugoslavia, as well. And, when that federation fell apart, Slovenia was largely spared the independence wars that raged in the 1990s. Slovenia transitioned smoothly from a socialism-based economy to capitalism. It joined the European Union in 2004.

Right after accession, Slovenia's economy was thriving: Construction was booming, banks were offered good terms for loans in international markets, and, in turn, funds were generously made available as low-interest loans. The country adopted the euro in 2007.

Watch video 01:06 Slovenia says can bail out banks alone

But it wasn't to last. "Slovenians relied heavily on loans in the years following EU accession," said Hermine Vidovic, of the Vienna Institute for International Economic Studies. "They incurred enormous debts abroad, funding a construction boom that came to an abrupt end in the financial crisis."

The tight relationship between political and economic structures in Slovenia posed further problems. Unlike other former socialist states in Europe, Slovenian government companies did not undergo large-scale privatization; many of them are still state-owned.

Vidovic said this gave rise to the suspicion that "decisions on loans are often made for political rather than economic reasons." Slovenes always wanted to be in control of their country, so they practically blocked foreign investment.

Tough austerity measures

In 2010, when lending conditions tightened, the economy ran into trouble. At times, it looked as though Slovenia would need international loans.

But it never came to that. Slovenia took the matter into its own hands and imposed tough austerity measures on the population to rescue the economy and the financial sector.

"On the one hand, the state budget was slashed, public sector salaries were cut and a whole series of savings and reform measures was passed," Vidovic explained. On the other hand, the state injected several billion euros into the country's unstable financial system — €1.55 billion ($1.83 billion) into the country's most important bank Nova Ljubljanska banka (NLB), which is state owned. To this day, the Slovenian government has not revealed where the billions came from.

In the midst of the crisis at the end of 2011, the government was ousted in a parliamentary vote of no confidence. The prime minister at the time, Borut Pahor, was not seen as someone capable of managing the crisis. His Socialist Party lost two-thirds of its seats in the following parliamentary elections. But that did not harm the perpetually smiling Pahor: only one year later, he won the presidential runoff election.

The photogenic president

Pahor digs his job — and he's got the social media savvy to show it

The tides have turned for Slovenia, which can once again be seen as a model of stability in the EU.

"In order for the Slovenian economy to recover, it was very important that a privatization program of 15 large companies, banks and infrastructure objects was launched in agreement with the EU," said Vidovic. Slovenian Telekom, the Port of Koper and Adria Airways, and Nova Ljubljanska banka (NLB) are among the companies that will be privatized.

For the people of Slovenia, this does not seem to be a problem. Exports are booming, unemployment will be around 7.5 percent this year — down one point compared to last year — and wages have been rising for the past two years.

All in all, it seems fitting that Slovenia is being led by a carefree president, a former model who posts pictures of himself on Instagram almost every day.