The dramatic development comes after several months of regular demonstrations calling for Mr 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 Mr Keita said his resignation was effective immediately and a banner across the bottom of the television screen referred to him as the “outgoing president”.
He said: “I wish no blood to be shed to keep me in power. I have decided to step down from office.”
He also announced his government and the National Assembly would be dissolved, certain to further the country’s turmoil amid an eight-year Islamic insurgency and the growing coronavirus pandemic.
Mr Keita, who was democratically elected in 2013 and re-elected five years later, was left with few choices after the mutinous soldiers seized weapons from the armoury in the garrison town of Kati and then advanced on the capital of Bamako.
The political upheaval unfolded months after disputed legislative elections, but Mr 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 suffered setbacks over the past year from Islamic State 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 reorganisation aimed at stemming the losses.
Tuesday’s developments have 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 coloniser France and the United Nations, which has maintained a peacekeeping mission in Mali since 2013, also had expressed alarm ahead of Mr Keita’s speech.
UN Secretary-General Antonio Guterres sought “the immediate restoration of constitutional order and rule of law,” UN spokesman Stephane Dujarric said.
Tuesday’s political turmoil threatened to further jeopardise security in Mali, where a 2012 coup allowed the Islamic insurgency to take hold amid a power vacuum.
But news of Mr 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.