Residents of Gabon's capital Libreville woke up to shots being fired and tanks patrolling streets early on Monday after military officers launched a coup attempt in the country.

A spokesman for Gabon's government said the chief military rebel who announced the coup attempt on state radio was arrested later on Monday.

Two of his accomplices were killed when security forces stormed the building, according to a statement by the presidency, and the remaining two were also in state custody.

"The situation is under control," the statement said.

Gabon's President Ali Bongo has been out of the country since October after suffering a stroke and is currently in Morocco receiving medical treatment.

Here's what you need to know about the tiny, oil-rich Central African nation and its leadership:

Who is behind the coup and what is its objective?

Lieutenant Kelly Ondo Obiang, the soldier who announced the seizure of power through national media, identified himself as deputy commander of the Republican Guard and president of the Patriotic Youth Movement of the Gabonese Defense and Security Forces.

According to his statement, the group had to take control because Bongo was physically and mentally incapable of ruling the country due to his health.

He criticised "the high military hierarchy" for failing to defend "the best interest of the nation" by tolerating the president's lies about his health, referring to a New Year's speech made in Morocco in which he claimed he was well.

The government of Gabon later Monday declared it was in control after it said four of the five plotters had been arrested.

"Calm has returned, the situation is under control," government spokesman Guy-Bertrand Mapangou said.

Ondo Obiang said the aim of the coup was to save democracy and preserve "the integrity of the national territory and national cohesion".

Describing the attempt as "Operation Dignity", he asked all security forces and the youth of Gabon to arm themselves and "take control of all means of transport, barracks, security checkpoints, armouries, airports".

Gabon will be ruled by "a national council of restoration" that will be set up shortly, Ondo Obiang said.

He said the coup was being carried out against "those who, in a cowardly way, assassinated our young compatriots on the night of August 31, 2016", a reference to deadly violence that erupted after Bongo was declared the winner of a disputed election.

What is Bongo's story?

France's closest ally in Africa, Bongo was a key figure in a murky network of trade and political ties between France and its former African colonies known as "FrancAfrique".

The Bongo family has ruled the oil-producing country for nearly half a century. Ali Bongo has been president since succeeding his father, Omar, who died in 2009 after ruling for 42 years.

Ali Bongo's re-election in 2016 was marred by claims of fraud and violent protest.

The 59-year-old president was hospitalised in October in Saudi Arabia after suffering a stroke. He has been in Morocco since November to continue treatment.

In his speech to mark the New Year, Bongo acknowledged health problems but said he was recovering. He slurred some of his words and did not move his right arm, but otherwise appeared in decent health.

Gabon has experienced a military coup once before. In 1964, army officers rose up against then President Leon Mba, but he took control back within days with the help of then French President Charles de Gaulle.

More than 150 of Mba's opponents were arrested following the incident with the president vowing to show "no pardon or pity".

Oil 'emirate' hits hard times

Gabon has been an oil producer since the 1960s, earning it the title of "Central Africa's little emirate".

Before the global slump in oil prices in 2015, black gold represented 45 percent of Gabon's gross domestic product (GDP), but this shot down to 27 percent in 2017.

An economic crisis since 2015 has led to a rise in unemployment, repeated strike action, companies operating on slowdown, and austerity measures being slapped on workers.

In a bid to reduce its dependence on oil, Gabon has looked to diversify its economy.

After taking power, Ali Bongo launched a string of construction projects, such as hospitals and roads, but several were halted because of a lack of funds.

Despite its rich natural resources, about one-third of Gabon's population still live below the poverty line.

Natural riches and people

Gabon's forests cover about 80 percent of its territory, hosting exceptional wildlife and biodiversity which the country has sought to exploit through eco-tourism, showing off its wild gorillas, chimpanzees, panthers, elephants and hippos.

In 2002, then President Omar Bongo created 13 new national parks that cover around 11 percent of Gabon to protect its wildlife and forests from excessive logging.

It is also the world's second-largest producer of manganese, and the forests provide 12 percent of global timber exports, including coveted tropical hardwoods.

Straddling the equator on Africa's Atlantic coast, Gabon shares its borders with Congo Brazzaville, Cameroon and Equatorial Guinea.

The former French colony spans some 268,000 square kilometres with a population estimated at about two million, according to the World Bank in 2017. One in two Gabonese is aged under 20.

Roughly 80 percent of its people are Christian while Muslims and animists account for the other 20 percent.

France's closest ally in Africa, Bongo was a key figure in a murky network of trade and political ties between France and its former African colonies known as "FrancAfrique".