NAIROBI, Kenya — On one side was a 76-year-old grandfather in a sunny yellow shirt and hat, who has held onto power in Uganda for 35 years by doling out patronage to preserve loyalty, while deploying his security forces to intimidate critics and muzzle the media.
On the other was a charismatic, 38-year-old rapper-turned-lawmaker, whose songs lamenting corruption and joblessness in the country became an anthem for a frustrated younger generation. He withstood beatings and arrests, and nights spent in jail to become the president’s most persistent challenger in years.
In the end — after a bitter and bloody campaign marked by a lethal crackdown on the opposition, an internet blackout and accusations of vote tampering and rigging — the president, Yoweri Museveni of Uganda, was declared victor of a sixth, five-year term in office. His rival, Bobi Wine, says the election was unfair, a contention backed by independent international observers.
For the world, Uganda’s election was a vivid demonstration of how autocrats use elections to cement their hold on power. For the country’s younger generation, and throughout Africa, it was a sign of how intractable the old systems are.
On Saturday, Mr. Wine was holed up in his house — which was surrounded on Friday by Mr. Museveni’s security forces — and declaring that Mr. Museveni had “fabricated” the election results.
“We rejected what they are putting out,” he said in a telephone interview from his home in Kampala, the capital. “We have our evidence, but they are keeping the internet shut down so that we don’t communicate it to the world,” he said, of the internet blackout that began days before the Jan. 14 election. “We won,” he added.
Local and foreign election observers questioned the validity and transparency of this week’s vote after they were prevented from monitoring it. The United States mission in Uganda said 75 percent of its accreditation requests had been denied, pushing it to cancel its observation of the vote.
A report seen by The New York Times, which had input from 2,000 observers with the Africa Elections Watch coalition deployed in 146 districts nationwide, documented late openings in most polling stations, incidents of illegally opened ballot boxes and the arrests of 26 members of civil society groups who were observing the election.
The Uganda electoral commission said Mr. Museveni received more than 5.8 million votes, or nearly 59 percent of the total, while Mr. Wine received 3.4 million votes, or 34 percent. There are 18.1 million registered voters out of a population of about 45 million.
Although Ugandan opposition candidates have faced crackdowns in the past, “the gag during this election was unprecedented,” said Su Muhereza, a Ugandan political commentator. “There was only so much one man like Bobi could do against the machine” of what she referred to as the security state.
For decades, Mr. Museveni’s deeply-rooted Western political and military connections cushioned him against direct scrutiny, even as human rights groups criticized his crackdown on critics.
Under his leadership, Uganda has been a close Western military ally in East Africa, with troops serving as peacekeepers in Somalia, where the authorities have battled the Qaeda-linked group al Shabab. Ugandan recruits have also served as private security guards and worked closely with American troops in Iraq and Afghanistan.
Mr. Museveni rose to power as the head of a revolutionary movement 35 years ago, promising to uphold democracy and safeguard the lives of Ugandans in a nation torn by coups and violence.
At the time, he and his cadres “saw themselves as the essential leaders, not just of the country’s politics, but of a whole new national culture,” said Derek R. Peterson, a professor of history and African studies at the University of Michigan.
As he consolidated power, Mr. Museveni and those in his government became more and more convinced that they alone had “the right to author Uganda’s destiny,” Mr. Peterson said.
“Where once he was a youthful firebrand,” Mr. Peterson said, Mr. Museveni “now speaks as an elder, reminding his people about the virtues of the old culture, demanding deference, excoriating the decadence of the young.”
In the voting on Thursday, many young Ugandans threw their support to Mr. Wine, whose real name is Robert Kyagulanyi. There were nine other challengers to Mr. Museveni as well, which split the opposition vote.
During the campaign, Mr. Wine called on Mr. Museveni to resign, pointing to the corruption, chronic unemployment and poor public services across the East African nation.
The authorities responded by arresting Mr. Wine — including on the day he filed for his candidacy in November — and charging him with violating restrictions to control the coronavirus pandemic.
The arrest of Mr. Wine and other opposition figures set off nationwide protests that led to the deaths of at least 54 people as security forces dispersed demonstrators. As the campaign heated up late last year, Mr. Museveni accused the opposition of being backed by foreign “agents” and “homosexuals,” and said they wanted to start an “insurrection” that would sow chaos across the country.
Citing government abuses, Mr. Wine in early January filed a case with the International Criminal Court against Mr. Museveni and nine top security officials, accusing them of attempted murder and human rights violations.
In the telephone interview, Mr. Wine said that between 50 and 60 military officers were still surrounding his seven-acre property and that they were blocking people from leaving or entering his home. Mr. Wine’s lawyer, Bruce Afran, said in a text message that Mr. Wine’s wife, Barbara, “was physically hauled back into the house by soldiers when she went to get vegetables from their garden.”
Mr. Wine said, “The government is doing this to intimidate me, to make sure I don’t speak to the world.” He added that he hoped the international community would stand up for Ugandans.
He said, “I am glad the world is getting to see Museveni for who he is.”