Mali's president said Wednesday he had resigned to avoid "bloodshed" after he was detained in a military coup, whose leaders pledged new elections to resolve a spiralling political crisis in the fragile West African nation.

Ibrahim Boubacar Keita's government had been beset by months of protests over economic stagnation, corruption and a brutal Islamist insurgency that has claimed thousands of lives.

Rebel soldiers took Keita and Prime Minister Boubou Cisse into custody on Tuesday afternoon and drove the pair to a military base on the outskirts of Bamako, which they had seized that morning.

Map of Mali locating Bamako and the Kati camp
Map of Mali locating Bamako and the Kati camp AFP / STF

Jubilant crowds were already gathered in the capital to demand Keita's resignation, and cheered the rebels as they made their way to the 75-year-old's official residence.

Keita appeared calm as he appeared in a state television broadcast soon after midnight to declare the dissolution of the government and national assembly, and said he had no choice but to resign with immediate effect.

"If it pleased certain elements of our military to decide this should end with their intervention, do I really have a choice?" he said of the day's events.

Anger: A demonstrator holds up a sign reading 'IBK out,' referring to President Ibrahim Boubacar Keita by his initials, in a protest in Bamako on August 11
Anger: A demonstrator holds up a sign reading 'IBK out,' referring to President Ibrahim Boubacar Keita by his initials, in a protest in Bamako on August 11 AFP / ANNIE RISEMBERG

"(I must) submit to it, because I don't want any bloodshed."

It was unclear whether Keita was still in custody at the Kati base, which in a twist of fate was also the site of the 2012 putsch that brought him to power.

The coup's leaders appeared on television hours later to pledge a political transition and new elections within a "reasonable time".

Under pressure: Keita faces mounting discontent at his handling of the economy and Mali's jihadist insurgency
Under pressure: Keita faces mounting discontent at his handling of the economy and Mali's jihadist insurgency POOL / Ludovic MARIN

Malian Air Force deputy chief of staff Ismael Wague said he and his fellow officers had "decided to take responsibility in front of the people and of history".

Mali's neighbours warned against any unconstitutional transfer of power as the coup unfolded on Tuesday.

The Economic Community of West African States (ECOWAS) condemned the coup in a statement, pledging to close land and air borders to Mali and push for sanctions against "all the putschists and their partners and collaborators".

Troops were cheered by crowds as they arrived at Independence Square in Bamako
Troops were cheered by crowds as they arrived at Independence Square in Bamako AFP / MALIK KONATE

The 15-nation bloc -- which includes Mali -- also said that it would suspend the country from its internal decision-making bodies.

UN Secretary General Antonio Guterres demanded the "immediate and unconditional release" of Keita and Cisse as diplomats in New York said the Security Council would hold emergency talks on Wednesday.

The United States and France also released separate statements voicing deep concern about the turn of events and urged against regime change.

French President Emmanuel Macron condemned the mutiny, according to his office, and said he supported mediation efforts to resolve the crisis by other West African states.

As the day unfolded, the United States and France released separate statements voicing deep concern about the turn of events and urged against regime change
As the day unfolded, the United States and France released separate statements voicing deep concern about the turn of events and urged against regime change AFP / STRINGER

The US envoy to the region, J. Peter Pham, joined the calls for restraint and echoed its opposition to any "extraconstitutional" change.

Keita and Cisse's sudden detention came on the heels of an apparently conciliatory message from the government in Bamako -- which had urged the soldiers to engage in dialogue.

"The observed shifts in mood reflect a certain frustration that may have legitimate causes," Cisse's office said in a statement, without offering further details.

It added that the government was open to "fraternal dialogue in order to remove all misunderstandings".

The drama coincided with opposition plans to resume protests against Keita.

The June 5 Movement, named for the date of its first protest, has channelled public anger against the leader that saw increasingly strident demands for his resignation.

The opposition campaign veered into crisis last month when 11 people were killed during three days of unrest sparked by a demonstration.

Mali is the linchpin of French-led efforts to roll back jihadists in the Sahel, and its neighbours are anxious to avoid the country sliding into chaos.

The failure to end that conflict fuelled frustrations with Keita's rule, analysts say.

Tensions flared in April when the government held a long-delayed parliamentary election, the results of which are still disputed.

ECOWAS last month suggested the formation of a unity government while sticking by Keita, but the compromise was bluntly rejected by the opposition.