Oumar Diakite was the hero as hosts Ivory Coast staged another remarkable salvage operation on Saturday to reach the Africa cup of Nations semi=finals, and South Africa later joined them.
A brilliant back-heel by the substitute in added time at the end of extra time in Bouake gave the Elephants a 2-1 victory over Mali, who dominated much of the quarter-final and scored first.
Ivory Coast-born Nene Dorgeles put Mali ahead on 71 minutes against the host nation, who were reduced to 10 men just before half-time when Odilon Kossounou was sent off.
But another Ivorian substitute, Simon Adingra, levelled in the 90th minute to take the pulsating west African showdown into extra time.
Then, with the quarter-final seemingly set to be decided by a penalty shootout, Diakite back-heeled a drive from a teammate past Mali goalkeeper Djigui Diarra.
Diakite, who had been yellow-carded earlier, took off his shirt when celebrating, leading to a second caution followed by a red card.
Victory came at a high price as suspensions rule Diakite, Kossounou, captain Serge Aurier and Christian Kouame out of a semi-final against the Democratic Republic of Congo on Wednesday.
"After this kind of match, there are no real things to explain, it is just emotions," said Diakite, who plays for French Ligue 1 outfit Reims.
"My joy was so great that I forgot that I had a yellow card. It was a mistake on my part. Even if I am not there, we can do the job (reach the final).
"With this goal, I think I put happiness on the faces of every Ivorian fan at the stadium. No words can describe how I'm feeling now, but I'm happy.
"We knew it was going to be a complicated match, but we made it difficult for ourselves. Our mentality played a key role in this triumph.
- 'Supporters incredible' -
"Our supporters are incredible and we had no option but to give our very best and seek victory, even if the red card before mine made it difficult."
Victory maintained the dominance of the Elephants over the Eagles in AFCON tournaments -- it was their fifth win from 1994 with one other meeting drawn.
The last time Ivory Coast reached the semi-finals was in 2015 in Equatorial Guinea, and they defeated DR Congo 3-1 before going on to win the tournament a second time.
Ivory Coast scraped into the knockout stage this time as the last of the four best third-placed nations and then trailed holders Senegal for 82 minutes before snatching an equaliser.
They went on to win the last-16 clash on penalties, only to be play second fiddle to Mali in the next round before staging an amazing comeback.
Mali contributed to their downfall by squandering a chance to take an early lead when Adama 'Noss' Traore had a penalty saved by Youssouf Fofana.
Several Malians could face disciplinary action as a group, including red-carded captain Hamari Traore, surrounded the Egyptian referee after the winning goal, forcing the official to push some away.
Meanwhile, South Africa goalkeeper Ronwen Williams saved four penalties in a shootout as his country beat Cape Verde 2-1 in a shootout after a 0-0 draw following extra time in Yamoussoukro.
Bryan Teixeira was the only Cape Verdean to score from the spot while Teboho Mokoena and Mothobi Mvala netted for South Africa.
South Africa are back in the semi-finals for the first time since 2000, when they lost to then co-hosts Nigeria, their opponents in Bouake on Wednesday.
Cape Verde could have won the match in added time at the end of regular time when Gilson Tavares broke through, but Williams pushed his shot on to the post and the ball was cleared.
On Friday, Nigeria edged Angola 1-0 through an Ademola Lookman goal and DR Congo came from behind to beat Guinea 3-1 with a late Arthur Masuaku goal from a free-kick sealing success.
Nigeria, who can call on reigning African Player of the Year Victor Osimhen, have won the AFCON three times, Ivory Coast and DR Congo twice each and South Africa once.