Bosnian Serb leader Milorad Dodik appeared on course for an election victory, preliminary results showed on Monday, after a chaotic election night that saw his rising rival also claim victory in a hard-fought race.

Hours earlier, the longtime leader of the Bosnian Serbs appeared poised to suffer a stunning defeat after his opponent Jelena Trivic clinched victory in the race for the presidency of the Republika Srpska (RS) – the country’s Serb entity.

According to the Bosnian Electoral Commission, Dodik had garnered 49 percent of the vote, compared to Trivic’s 42 percent, counting 82 percent of the entity’s polling stations.

“The latest results confirm our great victory,” Dodik’s SNSD party tweeted on Monday.

The close race was just one of a dizzying array of competitions in Bosnia on Sunday, with several upsets and the runaway results are likely to add fresh uncertainty to the troubled political scene.

Almost three decades after war devastated the Balkan country, Bosnia continues to be weighed down by its ethnic divisions.

The Balkan state was governed by a dysfunctional administrative system created by the 1995 Dayton Accords, which successfully ended the conflict in the 1990s but largely failed to provide a framework for the country’s political development.

Bosnia remains divided between a Serb entity and a Muslim-Croat federation, linked by a weak central government.

After the war, ethnic political parties have long exploited the country’s divisions to stay in power.

For years, Dodik has been stoking tensions with his frequent calls for Bosnian Serbs to further distance themselves from the country’s central institutions, earning him fresh sanctions from the United States in January.

Dodik is seeking his third term as RS President, having previously served in the tripartite presidency.

Trivic, a 39-year-old economics professor, tried to offer an alternative, running with an anti-corruption ticket while loudly trumpeting the Serbs’ desire to preserve their autonomy in Bosnia.

The fight for the RS presidency wasn’t the only surprise of the evening.

The race for the Muslim Bosniak seat in the country’s tripartite presidency saw another professor, Denis Becirovic, defeat two-time President Bakir Izetbegovic in a landslide victory.

The double-digit win was a sharp reprimand for Izetbegovic, who was a major figure in the post-war Bosnian political scene.