BAKU, Azerbaijan — Something funny happened the day before Azerbaijan’s presidential election: The election commission announced the winner.

On Tuesday, a day before the voting began, the smartphone app of the Central Election Commission released results showing President Ilham Aliyev, whose family has been at the helm of the Caspian Sea nation for four decades, winning 73 percent of the vote.

After the polls closed Wednesday, the commission said Aliyev had won 85 percent of the vote. His closest contender, Jamil Hasanli, trailed with less than 6 percent, it said.

The commission apologized for the early result, saying Thursday it had been only a test at one polling station conducted by the software developer. It expressed “deep regret” for the “misunderstanding.”

Hasanli called the vote rigged and demanded a new election.

Observers from the Organization for Security and Cooperation in Europe said Thursday the election was marred by restrictions during the campaign and serious violations during the voting and during the counting of votes.