JOHANNESBURG — President Edgar Lungu of Zambia eked out a victory in last Thursday’s elections, according to official results announced Monday afternoon. But his main rival disputed the impartiality of election officials and demanded a recount.

After an unusually violent campaign in a country considered one of Africa’s most stable democracies, Mr. Lungu garnered 50.35 percent of the vote, slightly over the threshold of votes to avoid a runoff. The main opposition candidate, a wealthy businessman, Hakainde Hichilema, won 47.67 percent of the total.

Commission officials had initially said that they would release final results by early Sunday, but the vote tallying took longer because of an unexpectedly large turnout. Mr. Hichilema’s party, the United Party for National Development, attributed the delay to Zambia’s electoral commission, accusing it of vote rigging.

In a news conference on Sunday, as incomplete results showed he was trailing behind the president, Mr. Hichilema cited irregularities in the count in Lusaka, the capital, and demanded a recount.