Group D winners Ivory Coast rescued a draw against Algeria to maintain their unbeaten record in the Nations Cup.
Algeria, eliminated before the match, missed a first-half penalty through Ryad Boudebouz but Sofiane Feghouli scored from a second spot-kick.
Substitute Feghouli then crossed for Hilal Soudani to power home a header to make it 2-0 before Didier Drogba nodded in superbly to halve the deficit.
A deflected Wilfried Bony shot completed the Ivorians' comeback.
It was a fightback that had looked in doubt as a reserve Ivory Coast side only raised their game once they went behind.
Aiming to go one better
Ivory Coast did not concede a goal in the 2012 tournament but still lost the final to Zambia - on penalties
With their quarter-final place already booked, having won the group before the game, Ivory Coast made wholesale changes to their team.
And it appeared to play into the Algerians' hands, who themselves were playing for pride having lost 1-0 to Tunisia and 2-0 to Togo, meaning they could not progress from the group.
The Desert Foxes had also failed to score in the tournament, but they were given a golden opportunity to do so when Ismael Traore brought down Soudani and the referee pointed to the penalty spot.
Boudebouz hit the kick well enough but it crashed back off the foot of the right post.
At that point the Ivorians - favourites to win the tournament - looked content to play within themselves and simply get through the match.
They did create a couple of first-half chances, with Salomon Kalou firing over when well placed and then Drogba, restored to the starting line-up, going close with a free-kick.
It all changed after the break as Algeria looked threatening immediately from the restart.
They had another great chance to take the lead when Boudebouz's free-kick was flicked on to Essaid Belkalem at the back post but he headed straight at the keeper.
But soon after they got their reward - and their second penalty of the game - when Arthur Bokam handled in the box and Feghouli made no mistake with his spot-kick.
It clearly boosted the Desert Foxes, who would at least go home having scored a goal, and they ventured forward with purpose.
Feghouli, an inspirational substitution, then turned provider as he delivered a pinpoint cross for Soudani to head home.
Down and out but not humiliated
Algeria avoided the embarrassment of going home without a point and without a goal
Algeria seemed rampant but Ivory Coast, who are one of the tournament favourites, responded in style.
Talisman Drogba got them started as he beautifully steered a header home from 12 yards.
And then fortune favoured the brave as Bony let fly with an ambitious, if inaccurate-looking effort, from outside the box that took a massive deflection and wrong-footed keeper Rais Mbolhi.
Ivory Coast even had a chance to snatch the win at the end but Drogba was off balance and overstretching as he tried to poke the ball in.
Not that the Elephants will be too concerned as they march on to face Nigeria in the last eight on Sunday.
Algeria coach Vahid Halilhodzic:
"After two games it's nice to have moved forward. We went through some very hard times. I asked my boys to give me a victory and we were not very far from that."
Ivory Coast coach Sabri Lamouchi:
"It was a good game despite the situation of both teams. What I appreciate the most is my players' reaction in the second half. They refused to lose, they didn't want to accept the defeat."
- 23 M'Bohli
- 02 Sbaa
- 04 Belkalem
- 05 Halliche
- 06 Mesbah
- 07 Boudebouz (Feghouli - 62' )
- 08 Lacen Booked
- 17 Guedioura
- 18 Lemmouchia (Tedjar - 86' )
- 09 Slimani
- 15 Soudani (Kadir - 82' )
- 01 Doukha
- 16 Si Mohamed
- 03 Cadamuro
- 12 Medjani
- 21 Ghoulam
- 22 Rial
- 10 Feghouli
- 11 Bouazza
- 14 Kadir
- 19 Bezzaz
- 20 Tedjar
- 13 Aoudia
- 16 Yeboah
- 03 Boka
- 04 K Toure
- 14 Traore
- 20 Lolo Booked (Eboue - 86' )
- 06 Romaric (Konan - 46' )
- 07 Razak (Zokora - 90' )
- 02 Kone
- 08 Kalou
- 11 Drogba
- 12 Wilfred
- 01 Barry
- 23 Sangare
- 17 Tiene
- 21 Eboue
- 22 Bamba
- 05 Zokora
- 09 Tiote
- 13 Konan
- 15 Gradel
- 19 Y Toure
- 10 Gervinho
- 18 Traore
Ref: Eric Otogo-Castane