Emmanuel Adebayor's first-half strike and a stoppage-time clincher from Dove Wome earned Togo their first win of the 2013 Africa Cup of Nations, 2-0, and sent Algeria out of the competition.
Both teams headed into the encounter having lost their opening Group D games, but now still have 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.
Algeria had two decent penalty shouts within 15 minutes of the restart, for challenges on Sofiane Feghouli and Slimani, but both were waved away by the referee.
Agassa did well to keep out a powerful effort from Guedioura in the 74th minute and, 10 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.
Thirteen minutes of stoppage time were 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.