Mali edged through to the Africa Cup of Nations semi-finals after beating co-hosts Gabon 5-4 on penalties.
The game had finished 1-1 after Mali's Tidiane Diabate cancelled out Eric Mouloungui's opener with five minutes left on the clock.
Neither side could break the deadlock in extra-time, and Mali knocked out the co-hosts after Pierre-Emerick Aubameyang missed his spot-kick.
Mali will now meet Ivory Coast in the last four in Libreville on Wednesday.
Gabon, who are co-hosting the tournament with Equatorial Guinea and have never reached the semi-finals, had looked on course for their fourth successive win at the tournament when Mouloungui scored from a pull-back pass from team-mate Aubameyang.
Earlier in the game, the Gabonese had squandered a host of chances as Aubameyang and captain Daniel Cousin both saw their shots bounce back off the post.
Mali, whose defence looked disorganised for much of the game, created few chances but might have equalised had Modibo Maiga not scuffed his shot.
However, the visitors snatched an equaliser when substitute Diabate struck in the 85th minute.
After extra-time passed without any goals, Seydou Keita scored the decisive kick in the shoot-out after Aubameyang had his effort saved.
The loss silenced the Libreville crowd, who had seen their team come within just minutes of a last-four place for the first time.
Mali and Barcelona midfielder Keita admitted his side's victory was not attractive, but that his team had done well to overcome the determined co-hosts.
"It was not easy but we have reached the semi-finals," Keita said.
"It was not Barcelona or Brazil but we worked within our capabilities."
Gabon coach Gernot Rohr, meanwhile, rued his team's missed opportunities, particularly Cousin and Aubameyang's efforts which hit the woodwork.
"Had those two chances gone in, it might have been a different result," Rohr said.
"It's very disappointing to lose in this way."