Togo put themselves back in contention in Group D at Algeria's expense, after beating the Desert Foxes in an engaging contest in Rustenburg.
Striker Emmanuel Adebayor put the Togolese ahead in the first half, coolly slotting under onrushing Algerian goalkeeper Rais Mbolhi.
Substitute Dove Wome doubled their lead in extended injury time, after referee Hamada Namplandraza added 13 minutes.
Algeria had dominated for long periods but were unable to find an equaliser.
The result leaves the North Africans unable to progress and ensures Ivory Coast's progression, after their earlier 3-0 win over Tunisia.
Hawks' soaring expectations
Togo's win over Algeria will raise hopes they can qualify for the knockout stages - at the seventh time of asking
Togo, meanwhile, go into their final group game with the Sparrow Hawks in a good position to qualify for the knockout stages for the first time.
Algeria were left frustrated by their inability to finish their chances - as they were in their opening 1-0 defeat by Tunisia.
The North Africans confidently played the ball around throughout, with playmaker Sofiane Feghouli at the heart of their attack, but met stiff resistance from the Togolese defence.
The Algerians earned their first of a number of free-kicks from good positions in the opening minutes, with Feghouli producing a delivery from the training ground, which Foued Kadir swiped well wide.
Togo were happy to sit deep and Jonathan Ayite released Adebayor for the first time, but the Tottenham striker couldn't reach the over-cooked pass ahead of Mbolhi.
Adebayor then rose highest to meet a floated ball to the far post, only for the ball to skim wide off his head.
Algeria came close to a breakthrough midway through the first half, with Feghouli once more the inspiration. Adlene Guedioura produced a powerful header from the Valencia midfielder's corner to force a good save from Togo keeper Kossi Agassa.
Just after the half hour mark, Adebayor punished Algeria for failing to take advantage of their early pressure, coolly controlling a strong header through by Moustapha Salifou and slipping the ball under Mbolhi.
Halilhodzic's historical ties
Algeria coach Vahid Halilhodzic is the former coach of Ivory Coast, who qualified on Saturday just as his Algerian side made their exit. He will meet his old side in their final group game
The Desert Foxes almost levelled minutes later - with Islam Slimani denied by Agassa, who made himself big in the Togo goal.
Vahid Halilhodzic's side started the second half on the front foot once more, with Feghouli's penalty shout denied by referee Namplandraza, after going down just inside the box, following a clip by Dakonam Djene.
Algeria continued to create, with Hilal Soudani heading wide from Foued Kadir's cross. Kadir once again tried to prise an opening for the Algerians but was just beaten to a header by Djene, with Soudani the provider this time.
They then saw another penalty appeal turned down, with Djene again felling Feghouli and the referee waving away further Algerian complaints.
Nottingham Forrest midfielder Guedioura elected for the direct route, bursting through the Togo rearguard but slashing wide from 25 yards.
Guedioura then followed up yet another Feghouli build-up, firing in a snapped shot, which Agassa once again collected.
Togo briefly broke up the Algerian siege, with Wome charging forward from his own half but shooting wildly over the bar.
The Sparrow Hawks then almost wrapped it up against the run of play, but Sapol Mani failed to find either Adebayor or Wome in the box.
There was a prolonged 15-minute delay at the end - which prompted 13 minutes of injury time - after Guedioura knocked the Algerian goal down by running into the back of the net.
The exhausted Algerians were unable to capitalise on the prolonged added time, but the Togolose managed to use it to their advantage, with Wome charging through from the halfway line and finishing neatly under Mbolhi to wrap up the victory and seal Algeria's fate.
Togo coach Didier Six:
"We were up against a very good Algeria team, but the win was deserved.
"Togo had the ambition to win.
"We have to recuperate now. We're in the 'group of death' and we have to put more effort into what we do."
Algeria coach Vahid Halilhodzic:
"Tonight was disastrous. I feel deeply ashamed. It's hard to analyse.
"We didn't play great football, but it's hard to blame anyone. I made the choices. I take responsibility for what happened.
"Now we'll sit down and think about the future of Algerian football."
Sorry, we were unable to load match stats, please try again.