Keita fires Mali into last eight
Mali finished second in Group D, behind Ghana, and set up a meeting on Sunday with co-hosts Gabon in Libreville.
Mali proved unconvincing in the match, watched by a 5,000 crowd, but Guinea's failure to beat Ghana in the other group game in Franceville ensured their progress.
Botswana scored first against the run of play with a sweeping move out of midfield, started and finished by Mogakolodi Ngele in the 51st minute.
He played a pass out wide and delayed his run into Mali's penalty box to arrive at the right moment and sweep the return ball home.
But Mali's pressure paid off six minutes later with Abdou Traore turning the defence before providing a cross that Modibo Maiga forcefully headed goal ward. Botswana goalkeeper Modiri Marumo could only parry it right to Garra Dembele who hammered home from close range.
"It was a huge lift for us to score then and the win means everything. We have a chance now to go all the way," Dembele told reporters.
Keita's goal was set up by his persistence on the edge of the penalty area as he probed an opening and then a return pass from Cheick Tidiane Diabate to perfectly place the ball into the roof of the net.
Ngele might have put Botswana level soon after but was selfish in going for a long-range shot instead of passing but Botswana pressed and ensured an anxious final few minutes for Mali.
They then had to wait for a full five minutes until Guinea's failure to beat Ghana was confirmed.
The Mali players stood anxiously waiting, watching pictures on the big screen before erupting in celebration.
"I was full of anguish at the end of the game having to wait. There is always this uncertainty, so I preferred to go back to the change room and wait patiently for the a outcome," said Mali coach Alain Giresse, who was in a similar situation at the last Nations Cup two years when in charge of Gabon.
Botswana depart after three successive losses but the experience for the debutants had proved invaluable, said midfielder Mogogi Gabonamon.
"We had a chance to compete in a tournament we never even dreamt of going to. That will be our history for the rest of our lives."