Ivory Coast fought back from two goals down to draw with Algeria in their African Nations Cup Group D dead rubber in Rustenburg.
Eliminated Algeria looked set to finish their tournament with an upset victory over already-qualified Ivory Coast thanks to second-half goals from substitute Sofiane Feghouli and El Arbi Soudani.
However, Ivory Coast, who might have been 3-0 down with Ryad Boudebouz missing an early penalty for Algeria, battled back with two goals in three minutes from Didier Drogba and Wilfried Bony to take a point.
The result leaves the Ivory Coast top of Group D with seven points and a quarter-final against Nigeria to look forward to, while Algeria head home with just one point to their credit.
By far the clearest chance for either side in a close-fought first half came in the seventh minute when Algeria were awarded a penalty when Ismael Traore dragged down Soudani after being turned by the Guimaraes forward on the edge of the box.
It provided Algeria with a perfect opportunity to notch their first goal since last October but it was spurned by Ryad Boudebouz as his drilled spot-kick smashed back off the base of the post.
Arguably Ivory Coast's best opening of the first period fell to Salomon Kalou but the Lille forward blazed high over the bar after creating space for a shot inside the area.
Drogba came close with a 25-yard free-kick in the 26th minute but that also failed to trouble Algeria goalkeeper Rais M'Bolhi as the first half finished goalless.
Algeria should have taken the lead straight after the restart but the unmarked Essaid Belkalem could only head straight at Daniel Yeboah.
However, Algeria did not have to wait much longer to go ahead after being awarded a second penalty in the 63rd minute for a handball by Arthur Boka as he attempted to block a cross.
Feghouli, who just moments before had replaced Boudebouz, took over the spot-kick duties and clinically fired his effort into the top corner.
It was 2-0 seven minutes later following another cross from the right, which this time found Soudani eight yards out and he powered home a header.
That looked to be game over, but last year's tournament runners-up were level within 10 minutes.
Drogba halved the deficit with a fine header from near the penalty spot in the 77th minute and then Bony levelled the scores up with a 25-yard strike which took a huge deflection before beating the wrong-footed M'Bolhi.