MEXICO CITY — Honduras was on the edge of political turmoil on Thursday, with the opposition candidate accusing vote counters of trying to “steal our victory” in an election whose results are sharply contested.

The candidate, Salvador Nasralla, said Wednesday that he would not accept the count of the country’s electoral commission, whose computer tally showed that President Juan Orlando Hernández had closed a gap that initially put Mr. Nasralla ahead in the voting that ended Sunday.

Mr. Nasralla’s statement that he would not accept the count represented an about-face from a letter he had signed a few hours earlier along with Mr. Hernández. Brokered by the Organization of American States, the agreement committed both men to respecting the commission’s results.

With ballots counted at about 80 percent of polling places, the candidates’ vote totals were almost even when Mr. Nasralla backtracked on the agreement. A final result is expected on Thursday.