With England beating Slovenia 1-0 in the other group game both the USA and Algeria looked down and out but, two minutes into stoppage time, Jozy Altidore, on the counter-attack, broke into the north African team's penalty area.
The former Hull City striker's cross led to a scramble inside the box and Algeria's goalkeeper Rais M'Bolhi could only parry a shot into the path of Donovan who calmly slotted the ball into the bottom corner to leave USA topping Group C.
- As it happened
- Slovenia 0-1 England
Algeria dominated the early stages of the match and, after five minutes, Rafik Zoheir Djebbour got clear of Jay DeMerit on the edge of the box and fired a shot against the crossbar.
The Stars and Stripes looked nervous in the opening minutes but, after 20 minutes, Clint Dempsey had the ball in the back of the net from three yards out after a cross from Herculez Gomez. However, the goal was wrongly ruled out for offside.
In the 36th minute Dempsey was through on goal but the Desert Foxes goalkeeper was able to make a vital block although the Fulham midfielder's shot was straight at M'Bolhi.
USA missed a glorious chance to take the lead a minute late. Donovan's effort was half-blocked by M'Bolhi but, with the Algerian goalkeeper in no-man's land, and with an open goal, Altidore's effort sailed over the bar.
Algeria sat back in the second half and looked to break on the counter-attack, but all the best chances fell to the USA. Altidore's pace troubled the Desert Foxes defence all match and, in the 57th minute, he was able to feed Dempsey through on goal but, after his first effort hit the post, his follow-up went wide with the goal gaping.
It looked like the United States were never going to score and they were heading for an early exit but Donovan's late goal moved them from third to first in Group C.
Algeria had more heartbreak to come as Anther Yahia was sent off a minute after the goal, as the Desert Foxes exited the tournament without scoring a goal.