Five months after Afghans went to the polls to choose a new president, election authorities have declared the incumbent, Ashraf Ghani, the winner, but his main opponent has rejected the result and said he will form his own “inclusive government”.

After a heavily contested poll, Ghani officially scraped just over 50% of votes, averting a second round run-off. But hours after the election results were announced, rival Abdullah Abdullah declared himself the victor.

Decisions on disputed votes were “illegal” he told a news conference in the Afghan capital, and the results “national treason”, local media reported.

The dispute sets Afghanistan up for a difficult political showdown at a critical time. The US is closing in on a withdrawal agreement with the Taliban, which should pave the way for “intra-Afghan talks” with the government in Kabul.

With two men claiming the presidency with powerful support bases, that vital but complicated stage in possible peace negotiations to end a decades-old civil war would be even more difficult.

“At a normal time, disputed election results would be traumatic for a country that craves stability and strong government, but this week, Afghans are also expecting a US-Taliban deal to be announced,” said Kate Clark, a co-director of the Afghanistan Analysts Network.

“That deal should usher in the start of talks between the Taliban and other Afghans. Will the Afghan political class be able to agree on a team or a negotiating strategy if they are locked in battle as to who sits in the presidential palace?”

September’s presidential poll was marred by violence and disillusionment with the political process, as well as fraud. Turnout was low; fewer than 2 million votes were counted even though Afghanistan has 9.6 million registered voters, election authorities said.

Although there were more than a dozen other candidates running in the 2019 election, Ghani and Abdullah were the only two with a real chance of victory. Both claimed they had won soon after polls closed, and accused the other camp of fraud.

Results that were originally to be announced on 7 November were delayed for months amid arguments over corruption, accusations of misconduct and technical problems counting ballots.

Since preliminary results in December put the incumbent in the lead, Abdullah’s allies have repeatedly warned they would consider a Ghani victory invalid because of fraud.

Abdullah’s powerful coalition for the vote includes the warlord Gen Abdul Rashid Dostum, who commands a huge and fiercely loyal following in the north of the country, and has threatened to set up a parallel government.

On Tuesday, election authorities said Ghani won 50.64% of the vote, or 923,592 ballots, while Abdullah received 39.52%, or 720,841 ballots.

Abdullah’s campaign chief hinted at use of force, if the dispute could not be resolved. “We are out of the election process,” Fazal Ahmad Manawi said on Twitter. “The reasons for this lack of legitimacy is clear to all as much as the sun is.

“Democracy, election and civil values is not functional in this country as whoever captures power tries to maintain it with any cunning possible. The only way for obtaining power is force.”

The election was a virtual replay of the 2014 contest, when Ghani and Abdullah were the main contenders and also argued bitterly over the result, trading accusations of fraud.

That impasse only ended when the then US secretary of state, John Kerry, stepped in to broker a power-sharing deal, paving the way for a largely dysfunctional “unity government” in which Ghani consolidated power while Abdullah struggled.

It is unclear if the US has the appetite for another diplomatic intervention, although having the withdrawal agreement within reach might make Washington more inclined to push for some kind of resolution of Kabul power struggles.