All four goals came in a 16-minute spell in the second half with Algeria taking the lead in the 64th minute with substitute Sofiane Feghouli scoring two minutes after coming on for Ryad Boudebouz, who missed a penalty in the first half.
They doubled their lead six minutes later when Hilal Soudani thundered in a header after escaping his marker and meeting a long perfect cross from Feghouli wide on the right.
The Ivorians, who had already qualified for the knock out stages before Wednesday's match, struck back in the 77th minute when Didier Drogba outjumped the defence to head home.
They equalised three minutes after that when a powerful shot from Wilfried Bony took a huge deflection off Algerian defender Djamel Mesbah.
Algeria were eliminated after losing their opening two games to Tunisia and Togo, while Ivory Coast boss Sabri Lamouchi rested nine players ahead of Sunday's quarter-final against Nigeria in Rustenburg.
Drogba returned to the Ivorian starting line-up but whether that was to give him more match time after his two-month layoff following the end of the Chinese season in November or because he is no longer regarded as a first choice striker will be seen when Lamouchi names his side to face Nigeria.
Drogba, who looked unimpressive in the opening two matches, did look far more involved in an admittedly low-key game, and should have scored five minutes before half-time but fired over the bar after cleverly creating an opening at the edge of the box.
His perseverance paid off and he made no mistake with his well-taken goal that brought Ivory Coast back into the game.
With little but pride at stake, the match took a long time to come to the boil, but the ending was dramatic as Ivory Coast showed some real character in the closing stages.
Gabon referee Eric Otoga-Castane may have treated Ivory Coast harshly for the first penalty when Soudani appeared to dive into the box.
But there was no mistake about the second when Arthur Boka handled, giving Sofiane the chance to lash the ball home from a two-step run-up.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.