Emmanuel Adebayor's first-half strike and a stoppage-time clincher from substitute Dove Wome earned Togo their first win of the 2013 CAF Africa Cup of Nations and sent Algeria tumbling out of the competition.
Both teams headed into the encounter at Rustenburg's Royal Bafokeng Stadium having lost their opening Group D games, and it was Didier Six' side who kept alive their hopes of reaching the quarter-finals.
Adebayor opened the scoring against the run of play in the 32nd minute and, during the early stages of the 13 minutes' stoppage time which were added after play was halted due to the frame of the goal being knocked out of line, Wome sealed matters.
Islam Slimani had half a sight of goal for Algeria in the 14th minute but lashed his right-footed shot wide. Kossi Agassa had to be alert midway through the first half, the Togo goalkeeper flying through the air to divert Adlene Guedioura's header around the post, and then getting down well to keep out Mehdi Lacen's deflected volley from the resulting corner.
Algeria were having the better of the chances but were unable to find the breakthrough, and Adebayor showed them how it was done just after the half-hour. The Tottenham frontman was afforded too much space as he latched onto Moustapha Salifou's header and coolly slotted a right-footed finish low past Rais M'Bolhi.
Slimani should have equalised nine minutes before the break but Agassa again got his body in the way to ensure Togo went in ahead at the interval.
Agassa did well to keep out a powerful effort from Guedioura in the 74th minute and, ten minutes later, substitute Yacine Bezzaz sent a rebound over the bar after El Arbi Soudani's shot had been blocked by team-mate Rafik Halliche, but that was as close as Vahid Halilhodzic's side got to restoring parity.
There was a lengthy stoppage in play towards the end while the goalposts were realigned after Nottingham Forest midfielder Guedioura fell into the net.
There were 13 minutes of stoppage time played following the disruption, giving Algeria further hope, but the only further goal arrived when Wome stroked a low shot past M'Bolhi to put the result beyond doubt.