Nationalist Tomislav Nikolic has been elected president of Serbia, with liberal incumbent Boris Tadic admitting defeat soon after polls closed.
Mr Nikolic has 50.21% of the vote, against 46.77% for Mr Tadic, with 40% of votes counted.
The contest had been seen as a vote on EU membership and the newly-elected president promised that "Serbia will not stray from its European path".
Mr Tadic appealed to keep "Serbia's strategic orientation towards the EU".
"It would be a tragic mistake if Serbia changes its orientation. It is a matter of peace and economic development," he said.
Speaking of Tomislav Nikolic, he added: "I congratulate him on the victory, it was a fair and well-earned victory and I wish him luck."
As he confirmed his commitment to Europe, Mr Nikolic claimed "This is a turning point for Serbia... these elections were not about who will take Serbia to the EU, but who will solve the economic problems created by the Democratic Party (of Boris Tadic)".
Serbia is plagued by unemployment of 24% and foreign debt of 24bn euros (£19.5bn; $31.5bn).
In the past Mr Nikolic served as a deputy prime minister under the former Yugoslav President Slobodan Milosevic, who was put on trial for genocide at The Hague.
He was in government when Nato bombed Serbia in 1999 and once said he would rather see the country ally itself with Russia than join the EU but he has softened his rhetoric in recent years.
He has tried to rebrand himself, and his Progressive Party has vowed to invest in agriculture and industry and tax the rich to fund a rise in pensions.
The election result is something of a surprise as the incumbent had been expected to win.
Speaking on RTS state television in Serbia political analyst Slobodan Antonic explained "this was an electoral earthquake, a totally unexpected result".
The BBC's central Europe correspondent, Nick Thorpe, says a low turnout of below 45% is thought to have damaged Mr Tadic's chances.
The outcome of the vote may affect both Serbia's EU prospects and the future of Kosovo, the breakaway Serbian province which declared independence in 2008.
A bitter row erupted after the first round of the election on 6 May, when the nationalists accused Mr Tadic's supporters of rigging the ballot.
Electoral officials found no evidence that 500,000 votes had been falsified, as Mr Nikolic alleged, while foreign monitors declared the vote to have been fair.
As president, Mr Tadic oversaw the EU candidacy negotiations and had argued that success for him and his Democratic Party was vital for development and stability in Serbia over the next decade.
Under his leadership, Serbia captured Bosnian Serb war crimes suspects Radovan Karadzic and Gen Ratko Mladic, and handed them over to international prosecutors at The Hague.