Tomislav Nikolic, a nationalist and former cemetery supervisor, was elected president of Serbia on Sunday, a surprising result that cast doubt on whether the country would remain on its path toward entry into the European Union or look increasingly eastward toward Russia.

With 41 percent of the vote counted, the official electoral commission said Nikolic, an ardent admirer of Russia who was once a close ally of the former Serbian strongman Slobodan Milosevic, won 50.2 percent of the vote compared with 46.7 percent for Boris Tadic, the former president who ran on a campaign advocating for Serbia's EU membership.

As was the case with the governing parties in Greece and France, analysts said that Tadic had suffered a backlash from many disillusioned voters who, hit by hard times, turned to Nikolic to express their discontent. Nikolic, a sometimes fiery populist, struck a chord with a growing underclass buffeted by the financial crisis.

Announcing his victory on Sunday night, Nikolic said he remained committed to Serbia's EU aspirations. "Serbia will not walk away from its path to the EU," he said.

Tadic conceded defeat Sunday night. "The people who voted gave their votes to Mr. Tomislav Nikolic," he said. "I wish him all the luck in his new function."

While Nikolic, a former ultranationalist, has in recent years professed a commitment to Serbia joining the EU and has called for close relations with the United States, analysts questioned whether a man who once feted war criminals would continue to push Serbia toward a pro-European path.

Only a few years ago, Nikolic, nicknamed "The Undertaker," presided over a party whose leader is on trial in The Hague for war crimes. He once said that he would rather see Serbia become a province of Russia than a member of the EU. But in recent years he has re-branded himself as a populist pro-European champion of the downtrodden, who favors strengthening ties with Brussels and the United States.

Nikolic's victory could presage a more hardened stance toward regional reconciliation, in particular with Kosovo, which declared independence from Serbia in 2008. While Tadic had offered concessions over Kosovo to help further Serbia's EU membership prospects, Nikolic has said that Serbia will not join the bloc if recognizing Kosovo is made a precondition for membership. Serbs consider Kosovo their medieval heartland.

The election comes at a critical moment for Serbia, which gained EU candidacy status in March. To help speed its entry to the bloc, Tadic overcame tough obstacles, including arresting Bosnian Serb wartime general Ratko Mladic, whose trial in The Hague began last week, and compromising over Kosovo.

But for all of his achievements on the international stage, Tadic presided over economic stagnation at home. Serbia, a country of 7.3 million people, is struggling with the effects of 24 percent unemployment, a weak currency, and an average monthly wage of around $500.