DAKAR, Senegal — Tuesday's stunning coup in Mali — in which mutinous soldiers stormed the capital and arrested the country's president — has opened a power vacuum that West African leaders sought to avoid, injecting instability into the heart of the fight against the world's fastest-growing Islamist insurgency.

Ibrahim Boubacar Keïta’s sudden ouster this week thrust the nation into chaos as it struggles to repel fighters loyal to al-Qaeda and the Islamic State. The militants have expanded their territory in the countryside during the pandemic, analysts say, despite military intervention from France and the United States.

The coup leaders revealed the first steps of their takeover on Wednesday on state television, pledging to build a civilian-led transition team, maintain ties with international partners and hold a new election.

“We can restore this country to its former greatness,” said Col. Maj. Ismael Wagué, a spokesman for the mutineers, without specifying candidates or a date for the election.

It was a dramatic cap to a turbulent two days in the country of about 20 million, after soldiers swarmed the capital on Tuesday morning and, by the evening, arrested Keïta and other top officials.

The embattled leader’s removal followed weeks of protests in Bamako led by the influential imam Mahmoud Dicko, who said again on Wednesday that he would not be seeking office.

Keïta’s opponents called him corrupt and blamed him for Mali’s biggest problems. People cheered as infantrymen rolled through town, flashing their guns from pickup trucks.

The nation’s global allies condemned the rebellion, which resulted in four deaths and 15 injuries, according to Amnesty International.

The African Union suspended Mali, and the Economic Community of West African States closed their borders with the country.

Five heads of state — the presidents of Nigeria, Ghana, the Ivory Coast, Niger and Senegal — had flown to Bamako this summer to negotiate with the leaders of the protest group aiming to eject Keïta.

This was the situation they wanted to prevent: more unrest in a region where deaths linked to terrorism have jumped fivefold since 2016, surpassing 4,000 last year, according to a U.N. tally.

Fatalities in the first six months of 2020 have nearly surpassed last year’s total, the Armed Conflict Location and Event Data Project reported Tuesday.

“The fight against terrorist groups and the defense of democracy and the rule of law are inseparable,” French President Emmanuel Macron tweeted Wednesday. “To get out of it is to provoke instability and weaken our fight.”

Attacks have surged during the pandemic, said Klaus Spreyermann, head of delegation for the International Committee of the Red Cross in Mali. Nearly a fifth of the country’s health-care facilities have been destroyed in the conflict — mostly centers serving people in remote areas.

“It remains the responsibility of authorities to assist them, no matter the changes of leadership in Bamako,” Spreyermann said in an email.

The violence has spilled into neighboring Burkina Faso, where 435,000 people have fled their homes since January, according to the U.N. refugee agency.

“Five percent of the country’s entire population — an astonishing 1 in 20 people — is now displaced,” UNHCR representative Babar Baloch said Tuesday during a news conference in Geneva.

France, which has more than 5,000 troops in the region, plans to hold its position, Macron said Wednesday. The United States provides military training and intelligence to Mali.

“The freedom and safety of detained government officials and their families must be ensured,” Secretary of State Mike Pompeo said in a statement Wednesday. “The United States calls on all political and military actors to work towards a restoration of constitutional government.”

Speaking through a surgical mask, Keïta announced his exit in an overnight broadcast, agreeing to dissolve the government, he said, to avoid more bloodshed.

It was a far cry from when the 75-year-old took power in 2013, promising to soothe tensions.

He enjoyed popularity at the start — sailing into the presidential palace after his predecessor, Amadou Toumani Touré, was sacked in a similar mutiny. The army had rejected Touré’s handling of the Tuareg rebellion in the north.

Both coups began at the same military base, Kati, about eight miles north of Bamako.

“Kati will no longer scare Bamako,” Keïta said at the time.

But Mali’s security crisis only worsened, and jobs shrank. People grew impatient for solutions.

“They are fed up with years and years of bad government,” said Flore Berger, a Mali analyst at the International Institute for Strategic Studies in London. “Keïta illustrates that. He’s taking the hit for that.

Mali’s army — about 12,000 soldiers — said last year that it lacked the equipment and funding to strike back against the militants, who rooted in the nation after the 2011 collapse of the Libyan government sent mercenaries and weapons over the border.

The extremists have complicated the battle by sparking conflict between ethnic groups in the countryside. Old neighbors accused each other of harboring the militants. And soldiers killed villagers during searches for the enemy, according to Human Rights Watch.

The fight has moved closer this year to coastal nations, including the Ivory Coast.

“There’s a risk of the armed groups taking advantage of this chaos to expand their operations in the region,” said Nadia Adam, a research officer at the Institute for Security Studies in Bamako. “A coup is instability.”

On Wednesday, the new army rulers closed Mali to the outside world, sealing air and land borders — and effectively cutting off trade — only weeks after the former government had lifted international travel restrictions related to the novel coronavirus.

Calm had returned to the streets, however.

Only a few dozen people showed up at the Independence Monument in Bamako by afternoon.

Abdou Gana, a 46-year-old travel agent in the capital, said he wasn’t concerned about the lack of planes in the sky or when they might return.

“Everyone is worried, and I know the burden of this responsibility is enormous,” Gana said, adding that he trusted the soldiers who have taken the reins. “But the whole world sees them in Mali, and I think they will live up to it.”

Mamadou Tapily in Bamako contributed to this report.