Host nation Ivory Coast produced another amazing Africa Cup of Nations escape act as Oumar Diakite's 122nd-minute winner sent the 10-man Elephants into the semi-finals at heartbroken Mali's expense.
The hosts played the majority of the game at a numerical disadvantage after Odilon Kossounou's dismissal for two first-half fouls on Lassine Sinayoko and they fell behind to Nene Dorgeles' classy curler.
But the Elephants equalised right on 90 minutes through Simon Adingra's opportunistic finish - and won it with virtually the last kick of extra time when Diakite diverted home Seko Fofana's shot.
Diakite left the field with mixed emotions, however, as a second yellow card received for removing his shirt in celebration means he will be banned for Wednesday's semi-final against DR Congo (20:00 GMT).
The final whistle yielded unsavoury scenes as several Mali players surrounded referee Mohamed Adel, remonstrating with the official, and Hamari Traore was shown a red card for taking his protests too far.
Listen to the World Football at Afcon podcast
From civil war in Ivory Coast to $1bn spend on Afcon
It was difficult to see what the Eagles were complaining about, as there appeared little wrong with the goal that sparked wild scenes of celebration at the orange-bathed Stade de la Paix.
A free-kick broke to Fofana on the edge of the area and, as his shot flew through a crowded goalmouth, Diakite, with his back to goal, instinctively stuck out a foot to flick the ball past Mali goalkeeper Djigui Diarra.
The quick thinking by the forward for French club Reims keeps the hosts' hopes of a third Afcon title alive after a barely-believable route through the competition that has seen them on the brink of elimination on several occasions.
Elephants find yet another escape route
Having come through the group stage by the skin of their teeth despite two defeats - and sacked manager Jean-Louis Gasset mid-tournament in the process - the knockout stages have been just as hair-raising for the hosts.
Under interim boss Emerse Fae, they came from behind, with another late goal, to force extra time and penalties to beat defending champions Senegal in the last 16.
But even that drama was completely eclipsed by Saturday's events in Bouake.
Fortune had again appeared to be on their side when Kossounou blocked Sikou Niakate's shot with an outstretched hand in the box but escaped punishment because the Mali man was offside in the build-up.
It took several minutes to clear up the confusion but when play restarted, Kossounou allowed Sinayoko to get the wrong side of him and bundled him over - only for Yahia Fofana to brilliantly save Adama Noss Traore's spot-kick.
Odilon Kossounou received a second yellow card for a trip on Lassine Sinayoko at the Afcon football tournament
Ivory Coast's Odilon Kossounou received two yellow cards for fouls on Lassine Sinayoko, one inside the area and the other just outside
The hosts' luck seemed to have finally run out when centre-back Kossounou, booked for the penalty incident, received a second yellow card for tripping the same player just before half-time.
However, they defended diligently, restricting Mali to efforts from distance, one of which paid off with just under 20 minutes to go as Dorgeles cut in from the left to find the top corner.
Unbowed, the Elephants responded admirably, Diakite and Wilfried Singo both going close with headers before a Fofana shot ricocheted perfectly for Brighton forward Adingra to stab Ivory Coast level from eight yards.
They continued to fashion the better chances in extra time, with Sebastien Haller heading against the bar before, with time almost up and another shootout looming, Diakite dramatically settled matters.
However, they must do without him against DR Congo in the last four - as well as Serge Aurier and Christian Kouame, who each collected a booking for the second successive game to trigger a one-match ban.
Mali's jinx against neighbours goes on
Mali will almost certainly have to answer to the African footballing authorities after the disgraceful post-match scenes with the referee but they only have themselves to blame for their exit.
They never really threatened to capitalise on their numerical advantage and sat back nervously even after Dorgeles gave them the lead.
From then on, they only created one real opening of note when the dangerous Dorgeles' extra-time ball across the box was almost turned into his own net by Nottingham Forest defender Willy Boly.
The Eagles will, of course, look back on the early penalty miss by Hull winger Traore, although it was an excellent save from Fofana, plunging quickly low and at full-strength to his left to keep the ball out.
Mali, who had topped their group unbeaten, had never before lost an Afcon quarter-final, winning all five times they had reached that stage, but were left to reflect on yet another defeat by their West African neighbours.
They have now lost 13 of the past 19 meetings between the countries, including a last-16 Afcon defeat in 2019, and this result, and the manner of it, will be a bitter pill to swallow for Eric Chelle's side.
Source: BBC
BDST: 1017 HRS, FEB 04, 2024
SMS