KABUL, Afghanistan — President Ashraf Ghani on Tuesday was declared the winner of Afghanistan’s presidential vote after five months of delayed results and bitter dispute. But the announcement threatened to tip the country into a full-blown political crisis on the cusp of a U.S. peace deal with the Taliban.

Just hours after the announcement, Mr. Ghani’s leading challenger, Abdullah Abdullah — who accuses Afghanistan’s election commission of favoring the incumbent — also declared himself the winner and said he would form a government of his own.

The dispute over the election result comes just after a breakthrough in the negotiations between the United States and the Taliban, with the two sides arriving at a tightly choreographed peace plan expected to be rolled out in a matter of days. The plan calls first for a test period of “violence reduction,” which would lead to the Taliban and Washington signing a deal. Soon after that, the two Afghan sides would sit down to discuss the political future of the country.

But Western diplomats have long feared that a political crisis in Kabul would weaken the Afghan government’s hand in the negotiations and affect the overall peace plan.