DAKAR, Senegal — First the president expressed shock. Then he refused to accept the results of the election.

It was late 2016, and Gambia’s ruler of 22 years — Yahya Jammeh — triggered global outrage when he rejected an unexpected loss to his political rival.

“I lament serious and unacceptable abnormalities which have reportedly transpired during the electoral process,” Jammeh said on state television at the time, offering no evidence.

The strongman appealed to the Supreme Court, asserting the contest was rigged.

Some in Gambia, the smallest country in mainland Africa, thought of that tense December night this week after President Trump falsely declared victory even as Democratic nominee Joe Biden pulled ahead.

“For us in Gambia, we were saying, ‘Trump is acting like Jammeh in 2016,’ ” said Sait Matty Jaw, executive director of the Center for Research and Policy Development, a pro-democracy group in the capital, Banjul.

It was one of the last times a world leader refused to step down after losing an election — a move swiftly condemned by defenders of democracy such as the United States, which has long positioned itself as a political expression role model and lambasted others who fall short.

Less than three months ago, Secretary of State Mike Pompeo put pressure on the tiny South American nation of Guyana after its former president blamed his fall from power on illegitimate votes.

“We know what makes a free and fair election,” Pompeo said. “It’s a central idea of every person gets to vote.”

On election night in the United States, vote counts showed an early lead for Trump across several battleground states. Optimism among Republicans chipped away, however, as officials began to tally millions of mail-in ballots — and Biden seemed to have a clear edge by Friday.

“STOP THE COUNT!” Trump tweeted, asserting without evidence that people had cast fraudulent ballots.

As Trump bashed the U.S. electoral process, his supporters gathered this week at election offices in states with tight races. Some of them brought guns.

Donald Trump Jr. tweeted that his father should go to “total war.”

“He is going against the very principles of democracy,” said Jaw, who followed the chaos on social media.

Back in 2016, Adama Barrow, then a 51-year-old businessman, stunned Gambia when he won 45.5 percent of votes for the highest office in the country.

Jammeh had garnered less than 37 percent.

The ruler had built a reputation for human rights atrocities. Gambia is investigating years of accusations against him — including extrajudicial killings by his personal squad of hit men — through its Truth, Reconciliation and Reparations Commission.

Initially, Jammeh conceded defeat and people celebrated his exit in the streets.

But the president who once asserted he would lead “for a billion years if Allah decrees it” quickly changed his mind. Leaving office meant he could be prosecuted for crimes. Jammeh faced accusations of stealing millions of dollars from state coffers, as well as rape and murder.

Unrest enveloped the country of roughly 2.4 million. Thousands fled into neighboring Senegal — including Barrow, the president-elect.

West African leaders tried to reason with him, but Jammeh wouldn’t listen. So troops from Senegal, Nigeria and Ghana ousted him in January 2017. He now lives in exile in Equatorial Guinea.

On social media Friday, a photo of Trump circulated with a slightly modified Jammeh quote: “I announce to you, Americans, my total rejection of the election results.”

For Latin Americans, Trump’s unfounded claims of fraud recalled the tactics deployed by both the right and the left for generations in efforts to cling to power.

Those attempts in recent years were reversed through international pressure, particularly from the United States.

Such was the case in Guyana.

Then-President David E. Granger, on the cusp of losing, baselessly blamed votes by dead people and noncitizens in the March elections.

“It is the first time this has happened in the history of our country,” Granger said in July, according to the Guyana’s Stabroek News. “It has happened because there are some bad elements out there who tried to manipulate the vote.”

After a laborious recount and a feud in the courts, Granger ultimately backed down after a five-month standoff, allowing opposition candidate Irfaan Ali to be sworn in as president in August.

That happened in no small part due to U.S. pressure.

 “The Granger government must respect the results of democratic elections and step aside,” Pompeo said in July as he announced new visa restrictions on “individuals responsible for or complicit in undermining democracy in Guyana.”

The irony of Trump’s resistance was not lost on the Guyanese. One meme circulating on the local Internet there Friday showed Trump phoning Guyana’s indicted election chief, Keith Lowenfield.

“Yo Lowenfield help me out bro. Joe Biden leading,” Trump says in a caption.

“Sure no problem but you have to gimme back my visa,” Lowenfield replies, referencing the U.S. penalty imposed on him for the disputed vote.

Faiola reported from Miami.