Gambians celebrate the victory of opposition candidate Adama Barrow by tearing down a poster of longtime President Yahya Jammeh in the streets of Serrekunda, Gambia, Dec. 2, 2016. (AP Photo/Jerome Delay) (Jerome Delay/AP)

One of Africa’s longest-ruling leaders, Gambia’s mercurial and iron-fisted President Yahya Jammeh, was voted out in a stunning election loss more than 20 years after seizing power in a military coup, ballot results showed Friday.

The outcome — and indications that Jammeh would accept the voters’ will — stood in sharp contrast to the numerous African nations where strongman rulers have recently imposed changes that effectively guarantee their hold on power, sidelining the opposition.

Jammeh was defeated by Adama Barrow, an estate agent and former security guard with little political experience. Few imagined that he would topple Jammeh, who has controlled the tiny West African country of 2 million since 1994 and who once vowed to rule for “1 billion years, if God wills.” Despite its small size, more people have fled to Europe from Gambia than from almost any other country in Africa, leaving behind poverty and a repressive political climate.

Until the last minute, when Gambia’s election commission announced the results, many Gambians assumed Jammeh would find a way to declare himself the victor.

Internet and phone lines were cut in parts of the country, adding to speculation that Jammeh’s regime was laying the groundwork to stay in power. Jammeh had jailed his political opposition for years, and it seemed likely that he would take measures to maintain his grip.

Supporters of President-elect Adama Barrow celebrate his election victory in Banjul, Gambia, Dec. 2, 2016. REUTERS/Thierry Gouegnon TPX IMAGES OF THE DAY (Thierry Gouegnon/Reuters)

But as the vote tally became clear, the election commission chief, Alieu Momar Njie, announced that Jammeh would concede.

“It’s unique that someone who has been ruling this country for so long has accepted defeat,” Njie told reporters in Banjul, the capital.

Jammeh has been one of the world’s most unpredictable, and often incoherent, leaders.

He declared that he had found a cure for AIDS consisting of local herbs. He gave himself the quixotic title of “Conqueror of Rivers.” His face was plastered on billboards across the country. People spoke about him in whispers, worried that one of the government’s plainclothes spies might be listening.

This year, he withdrew from the International Criminal Court, which his minister of information called the “International Caucasian Court,” implying that it was a Western institution biased against Africans.

Though he was widely mocked for his far-fetched pronouncements, there was a vicious dark side to his rule.

He threatened to personally slit the throats of gay men. His failed efforts to boost the country’s agricultural productivity left millions of Gambians in poverty, with few prospects other than to migrate to Europe, which a disproportionate number of them have done. By October, more than 10,000 Gambians had arrived in Italy in 2016 alone, according to the U.N. High Commissioner for Refugees, making Gambia the fifth-largest source of refugees in all of Africa, even though it has one of the smallest populations.

Jammeh shrugged off the huge exodus, saying that “true Muslims” would persuade their children to stay in the country.

But it appears that the same desperation that prompted thousands of Gambians to flee has now led to Jammeh’s electoral upset.

“Gambians were tired of dictatorship, tired of being poor, tired of being a pariah in the region,” said Jeffrey Smith, founding director of Vanguard Africa, a nonprofit organization that has worked closely with the opposition. “It’s certainly a shot across the bow for entrenched, abusive governments across Africa.”

In recent years, the leaders of Rwanda, Burundi, Congo and Sudan have changed their constitutions or cracked down on their opponents to extend their rule.

Barrow, leader of his country’s United Democratic Party, had spent several years in Britain as a department store security guard. He returned to his native country and rose through the ranks of the fledgling political opposition, whose leaders were frequently jailed by Jammeh’s government.

In July, opposition leader Ousainou Darboe and 18 others were sentenced to three years in prison for taking part in an unauthorized demonstration. In April, another opposition leader, Solo Sandeng, was allegedly beaten to death by members of the Gambian security services, according to witnesses, after being arrested for leading a demonstration in favor of electoral reform. The government later acknowledged Sandeng’s death in an affidavit, saying it was caused by “shock” and “respiratory failure.”

“Alhamdulillah,” or “Praise be to God” in Arabic, Sandeng’s daughter wrote on Facebook after the election results were announced.

Unlike in previous Gambian elections, all of the county’s splinter opposition groups united behind Barrow, giving him the groundswell of support he needed to defeat Jammeh.

That support was evident Thursday as voters dropped marbles in different-colored buckets, each associated with a different candidate. On Friday, the marbles were counted.

Barrow had 263,515 votes. Jammeh had 212,099. Jammeh had not yet publicly conceded, but the electoral commission said he soon would.

It took only minutes for people to begin dancing in the streets.