BELGRADE, Serbia - Serbia's pro-Western president won a closely contested election Sunday, edging an ally of late autocrat Slobodan Milosevic days before an expected declaration of independence by the breakaway Kosovo province.

President Boris Tadic won 51 percent of the vote, while Tomislav Nikolic, who ruled with Milosevic during the wars in the Balkans in the 1990s, had 47 percent, according to the state electoral commission.

"Serbia has shown its great democratic potential," Tadic said in his victory speech, praising Nikolic for "the number of votes he has won."

Nikolic congratulated Tadic but added, "I will remain to be his tough opposition."

Tadic's supporters celebrated in downtown Belgrade, waving Serbian, EU and Democratic Party flags and honking car horns.

The outcome indicated that a majority of Serbians want the country to stay on its path of pro-Western reform and closer ties with the European Union, instead of heading back to the nationalism and isolation that characterized the Milosevic era.

Nikolic's defeat will also likely alleviate fears in the West that Serbia would react violently to Kosovo's expected declaration of independence later this month.

Both Tadic and Nikolic oppose the province's independence, but Tadic has ruled out the use of force and will likely seek to preserve close ties with the EU and the United States even if they recognize Kosovo statehood.

The province, dominated by pro-independence ethnic Albanians, has been run by the United Nations and NATO since the 1998-99 war, when NATO bombed Serbia for 78 days to stop his brutal crackdown against Kosovo separatists.

Kosovo's Albanian leaders said they would declare independence days after the Serbian runoff, no matter who wins, and they expect the U.S. and most EU countries to follow up with quick recognition.

While pledging never to recognize Kosovo independence, Tadic has said there is "no alternative" to EU membership for Serbia.

Nikolic has insisted that Serbia must abandon its EU membership bid if the bloc upholds Kosovo's independence and should turn to its ally Russia instead. He has advocated measures including armed intervention to protect minority Serbs in the province.

Mladjan Dinkic, the leader of the pro-Western G17 Plus party allied with Tadic, said the president's re-election gave him the legitimacy to lead the country toward the EU.

"There is no chance any more for anyone to put any obstacles on that road because the citizens gave it the legitimacy," Dinkic said.

The European Union was quick to congratulate Tadic.

The EU "welcomes the fact that the Serbian people seem to have confirmed their support to the democratic and European course of their country," the bloc said in a statement.

Voters in Belgrade said the balloting was crucial.

"We have just recovered a little, we must not stop now," says Dusan Andjic, a 40-year-old lawyer who voted for Tadic. "This is really a matter of life and death."

Nikolic's supporters said Serbia's pro-Western leaders were going to sell out the country.

"If we don't stop them, they will give away Kosovo," said Marko Stipcevic, 51, a clerk.

Serbia's presidency is formally a ceremonial post, though it gained in importance and influence under Milosevic's virtually unrivaled rule in the 1990s.

A victory for Nikolic -- whose party boss Vojislav Seselj is now on trial for alleged war crimes at the U.N. tribunal for the former Yugoslavia -- would have dashed Western hopes that Serbia will arrest two Bosnian Serb war crimes fugitives, Gen. Ratko Mladic and his wartime political leader Radovan Karadzic, any time soon.

Tadic's Democratic Party played a key role in Milosevic's ouster from power in 2000. The soft-spoken party leader first became the president in 2004, by beating Nikolic in a runoff election.