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.
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.
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."