BAMAKO, MALI – Malian President Ibrahim Boubacar Keita announced his resignation late Tuesday on state television, hours after mutinous soldiers fired shots into the air outside his home before detaining him and the prime minister.

The dramatic development comes after several months of regular demonstrations calling for Keita to step down from power three years before his final term was due to end.

Speaking on national broadcaster ORTM just before midnight, a distressed Keita wearing a mask amid the COVID-19 pandemic said his resignation was effective immediately. A banner across the bottom of the television screen referred to him as the "outgoing president."

"I wish no blood to be shed to keep me in power," Keita said. "I have decided to step down from office."

He also announced that his government and the National Assembly would be dissolved.

Keita, who was democratically elected in 2013 and reelected five years later, was left with few choices after the mutinous soldiers earlier in the day seized weapons from the armory in the garrison town of Kati and then advanced on the capital of Bamako.

There was no immediate comment from the troops, who hailed from the same military barracks in Kati where an earlier coup originated more than eight years ago.

The political upheaval unfolded months after disputed legislative elections, but Keita's support also had tumbled amid criticism of his government's handling of an Islamic insurgency that has engulfed the country once praised as a model of democracy in the region.

The military has taken a beating over the past year from ISIS and al-Qaida-linked groups. A wave of particularly deadly attacks in the north in 2019 prompted the government to close its most vulnerable outposts as part of a reorganization aimed at stemming the losses.

Tuesday's developments already had been condemned by the African Union, the United States, and the regional bloc known as ECOWAS that had been trying to mediate Mali's political crisis. Former colonizer France and the United Nations, which has maintained a peacekeeping mission in Mali since 2013, also had expressed alarm ahead of Keita's speech.

U.N. Secretary-General Antonio Guterres sought "the immediate restoration of constitutional order and rule of law," U.N. spokesman Stephane Dujarric said.

Tuesday's political turmoil threatened to further jeopardize security in Mali, where the 2012 coup allowed the Islamic insurgency to take hold amid a power vacuum.

But news of Keita's detention was met with celebration throughout the capital by anti-government protesters who first took to the streets back in June to demand that the president step down three years before the end of his final term.

The detention was a dramatic change of fortune for Keita, who seven years earlier emerged from a field of more than two dozen candidates to win Mali's first democratic post-coup election in a landslide with more than 77% of the vote.

Regional mediators from ECOWAS, though, had failed in recent weeks to bridge the impasse between Keita's government and opposition leaders, creating mounting anxiety about another military-led change of power.

Then on Tuesday, soldiers in Kati took weapons from the armory at the barracks and detained senior military officers. Anti-government protesters immediately cheered the soldiers' actions, some even setting fire to a building that belongs to Mali's justice minister in the capital.