Morocco 3-1 Algeria
By Farayi Mungazi
BBC Sport, Sfax
Extra-time goals from Youssef Hadji and Jaouad Zairi booked Morocco a semi-final place after a dramatic clash with Algeria.
Underdogs Algeria looked to have won it when Abdelmalek Cherrad headed home Hocine Achiou's cross on 81 minutes.
But Morocco deservedly drew level four minutes into stoppage time as Marouane Chammakh lashed home unmarked from Mohamed Yaacoubi's run and cross.
Substitute Hadji then fired in from a tight angle before Zairi sealed victory with a late breakaway goal.
The turnaround saw the Atlas Lions secure their first appearance in the semi-finals of the Cup of Nations since hosting the tournament in 1988.
The late intervention of Hadji and the impressive Zairi deservedly set up a showdown with Mali on Wednesday.
Yet the Algerians appeared to have stolen the tie when Cherrad found the target with seven minutes remaining.
He headed home a cross from Achiou which had deflected into his path from Moroccan defender Talal El Karkouri.
But Chamakh pulled the game out of the fire with a stoppage-time equaliser.
After being left unattended inside the six-yard box, he beat a cruelly exposed Lounes Gaouaoui in the Algerian goal with ease.
Cherrad heads Algeria in front after 81 minutes
It would have been an injustice to Morocco had they failed to take the game into extra-time, as they were in complete control from the first shrill of Libyan referee Hakim Abdul Shelmani's whistle.
The overwhelmingly Algerian crowd at the Taieb Mhiri stadium in Tunisia's second biggest city did its utmost to unsettle the Moroccans, jeering their every touch of the ball and throwing the occasional missile onto the pitch.
But in the face of such extreme provocation, the Atlas Lions remained calm and took the game to the Desert Foxes.
In keeping with the nature of a North African derby, the referee was a busy man and booked three players inside the first 15 minutes.
On the whole, an unconvincing first half yielded nothing more than stray passes and untidy marking as both sides struggled to find any attacking rhythm.
Only the dazzling footwork of Moroccan star Zairi down the left flank gave fans something to talk about at the break.
With goal-poacher-in-chief Achiou playing below par and - at times - at sea with both opponents and team mates, the Algerians struggled to get beyond the half-way line for most of the match and Khalid Fouhami in the Moroccan goal was rarely needed.
But as Morocco piled on the pressure in the second half, they were stung by a classic counter-attacking move which ended with Cherrad's fine headed goal.
But just as Algeria appeared to be heading for Wednesday's semi-finals, Chammakh stunned the crowd into silence with the goal that took the match into extra-time.
Morocco: 1-Khalid Fouhami; 4-Abdeslam Ouaddou, 6-Noureddine Naybet (captain), 5-Talal El Karkouri (20-Youssef Hadji 86); 2-Walid Regragui, 8-Abdelkrim Kissi (11-Mohamed Yaacoubi 69), 15-Youssef Safri, 16-Youssef Mokhtari, 13-Houcine Kharja (19-Jamal Alioui 90); 7-Jaouad Zairi, 17-Marouane Chammakh
Algeria: 12-Lounes Gaouaoui; 4-Samir Beloufa, 5-Salim Aribi, 21-Antar Yahia; 6-Yazid Mansouri, 8-Nasredine Kraouche, 10-Djamel Belmadi (c) (15-Karim Ziani 72), 22-Hacine Achiou, 19-Mamar Mamouni (13-Brahim Zafour 98); 11-Mansour Boutabout (9-Nassim Akrour 78), 7-Abdelmalek Cherrad
Referee: Shelmani Abdul Kakim (Libya)