A group of military officers said they had seized power in the oil-rich Central African nation of Gabon early Wednesday, overturning the results of a disputed election that returned the incumbent, President Ali Bongo Ondimba, for a third term in office.

Appearing on a state-run TV station early on Wednesday, a few hours after Mr. Bongo was declared the winner of last weekend’s vote, the officers declared they were annulling the result, suspending the government and closing Gabon’s borders until further notice.

There was no immediate reaction from Mr. Bongo, one of France’s closest allies in Africa, or his government. Bursts of gunfire were heard in the capital, Libreville, from the vicinity of the presidential residence, shortly after the broadcast ended.

“We have decided to defend the peace by putting an end to the current regime,” a spokesman for the mutineers said on the state-run television station, Gabon 24.

Hours later they announced Gen. Brice Oligui Nguema, head of the Republican Guard, the elite unit charged with protecting Mr. Bongo, as the leader of the junta. Mr. Bongo and his family were being held at their residence, they said. Several senior advisers including one of his sons, Noureddin Bongo Valentin, had been arrested.

Footage posted to social media showed chanting soldiers hoisting General Oligui onto their shoulders outside the presidential complex, and punching their fists in the air.

General Oligui then drove through Libreville where he was greeted by crowds of jubilant coup supporters, some shouting “freedom!”

“Thank you, thank you,” the coup leader said at one stop, before driving off.

If it succeeds, the unexpected coup in Gabon would be the latest in an extraordinary run of military takeovers in Western and Central Africa — at least nine in the past three years, including one last month in Niger where President Mohamed Bazoum was also overthrown by head of his presidential guard.

The coup was also a new blow to France, the former colonial power in Gabon, and its wider influence in Africa. The Bongo government has been among France’s staunchest allies in Africa for decades, an embodiment of the lingering French influence known as Françafrique, even as its hold in other former colonies waned. French companies dominate Gabon’s oil and timber industries, and 400 French troops are based in the country, many at the Camp de Gaulle military base in Libreville.

France condemned the ongoing coup, Olivier Véran, the French government spokesman, told reporters on Wednesday morning. The French government “reaffirms its wish that the outcome of the election, once known, be respected,” he said.

Eramet, a French mining group that employs 8,000 people in Gabon, said it was suspending its operations. On social media, France’s embassy in Gabon recommended that its citizens in the country stay at home.

China, which accounts for about half of Gabon’s exports, also expressed concern. A Foreign Ministry spokesman in Beijing appealed for calm and called on “all sides” to ensure Mr. Bongo’s safety.

Russia, which has deployed Wagner mercenaries to several African countries following coups in recent years, also expressed concern. Wagner is not thought to be present in Gabon, although it has a presence at a major port in neighboring Cameroon.

Many of the recent takeovers in Africa occurred in countries that had been destabilized by insurgent violence, like Mali and Burkina Faso, or by intramilitary tensions, like Sudan. But the coup in Gabon was aimed squarely at one of Africa’s most enduring political dynasties.

The Bongos have ruled Gabon for over half a century. Mr. Bongo, 64, was about to begin his third term since becoming president in 2009. He took over from his father, Omar Bongo, who had been in power since 1967.

The voting last weekend was tense, with loud opposition claims of rigging and fears that, as in many previous elections in Gabon, it would end in violence. Many people had left the capital for the weekend, fearing trouble. After the polls closed, the government imposed a nightly curfew and restricted internet access.

Around 3 a.m. on Wednesday, the national electoral authority declared on television that Mr. Bongo had won the election with 65 percent of the vote. It said his main rival, Albert Ondo Ossa, had got 31 percent.

Moments later, gunfire was heard in the center of the city, residents said. Soon after that, the mutinous officers, calling themselves the Committee for the Transition and Restoration of Institutions, appeared on Gabon 24 and announced that they were “putting an end to the regime.”

Denouncing what he called “irresponsible and unpredictable governance” under Mr. Bongo, a spokesman for the group declared on television: “People of Gabon, we are finally on the road to happiness.”

But the statement offered few clues about the group’s level of support inside the military, or its intentions for Gabon, which is Africa’s seventh-largest oil producer and a member of OPEC.

Like the coup leader, General Oligui, many of the putschists wore the uniform of the Republican Guard. Just a few weeks ago, General Oligui received a new delivery of French armored vehicles that bolstered his unit’s reputation as the most powerful in Gabon’s military.

Residents identified one of the mutineers as a former aide-de-camp to Mr. Bongo.

The attempted coup came as a surprise in Libreville, where residents woke up on Wednesday to news of potentially momentous change after a half-century under the Bongo family. Even so, there was a semblance of normality in the center of the city, where shops opened and traffic circulated. The internet was working.

A spokesman for Mr. Bongo could not be reached.

President Emmanuel Macron of France hosted the French-educated Mr. Bongo in Paris in June, when the two leaders were pictured smiling together. That was a welcome show of unity at a time when France is grappling with a wave of anti-French sentiment in former colonies in Africa.

In Mali and Burkina Faso, recently installed military juntas have compelled Paris to withdraw its diplomats and thousands of soldiers. France has backed threats by a bloc of West African states to take military action against the junta in Niger, which has been holding the deposed president, Mohamed Bazoum, since his ouster in late July. And last week the junta ordered the French ambassador, Sylvain Itte, to leave by Sunday night. As of Tuesday, he was still in the country.

In recent years Gabon has emerged as a leader in the lucrative new market for carbon credits. Nearly 90 percent of the country is covered in rainforest, an asset that Mr. Bongo sought to monetize by selling credits potentially worth billions of dollars to foreign businesses and governments.

Despite those riches, poverty is endemic in Gabon, where half of the population is under age 20. Nearly 40 percent of Gabonese of ages 15 to 24 are unemployed, according to the World Bank.

Elian Peltier contributed reporting from Niamey, Niger, and Aurelien Breeden from Paris.