Landon Donovan struck an injury-time winner as the United States sensationally progressed through to the last 16 of the World Cup with a deserved win over Algeria, who crash out.
The United States, watched on by former President Bill Clinton, dominated for large periods and created a host of chances but looked set to be denied by a mixture of the woodwork, good goalkeeping and poor finishing.
However, Donovan popped up right at the end to slot into the net to send the Americans through as Group C winners ahead of England, who beat Slovenia in the other game, The United States will now play the second-placed team from Group D, which includes Ghana, Germany, Serbia and Australia.
For Algeria, who have never progressed to the last 16 of the World Cup, they hit the woodwork early on and created a couple of other chances but were unable to net their first goal of the finals as they tumbled out.
They also finished with 10 men after captain Anthar Yahia was sent off for a second booking late on in Pretoria.
Algeria coach Rabah Saadane, knowing his side could not afford a third successive match without a goal, made one change to the team that held England 0-0, bringing in AEK Athens striker Rafik Djebbour for Ryad Boudebouz.
USA boss Bob Bradley, meanwhile, made three changes. Algeria started brightly and almost took the lead in the sixth minute when Djebbour rattled the crossbar.
US defender Jay DeMerit failed to cut out a long punt forward and Djebbour stole in behind him, controlled the ball on his chest before smashing a volley against the crossbar from 12 yards out.
It was also a big let-off for the Americans, but Bradley's side would return the favour with interest during the remainder of the period as they spurned a number of good chances themselves.
Herculez Gomez brought a save out of Rais M'Bohli, before the US thought they had taken the lead in the 20th minute when Gomez, having seen his first effort saved, saw his cross-shot turned in at the far post by Clint Dempsey.
However, the effort was chalked off for a marginal offside.
The Americans were denied a winning goal in their last match against Slovenia when Maurice Edu's late strike was controversially chalked off.
After a slow start, the US were starting to look increasingly dangerous and they created two great chances around the 35th minute.
Dempsey saw the first saved by M'Bohli after being put through by a great pass by Donovan, and then Jozy Altidore blazed horribly over after the influential Donovan had dinked the ball past M'Bohli to set up a magnificent opening.
The Desert Foxes were still posing problems of their own though, and Karim Matmour earned a corner after testing Tim Howard with a long-range thunderbolt as the half ended in stalemate.
With England leading Slovenia in the other game, both the US and Algeria were on their way out of the World Cup at the interval.
The Americans should have improved their lot in the 56th minute though as they spurned another great chance.
The ball fell invitingly for Dempsey on the edge of the box, but his shot rebounded back off the inside of the far post before the Fulham midfielder sliced the rebound wide with the goal gaping.
Bradley's side continued to dominate and Benny Feilhaber went close before his fellow substitute Edson Buddle powered a header straight at M'Bohli from five yards out.
Algeria briefly stemmed the one-way traffic when Karim Ziani dragged a shot wide from a good chance in the 69th minute, but otherwise it was largely all America.
Algeria had a late chance to snatch what could have been a winner when Rafik Saifi headed straight at Howard, and moments after that the US claimed the victory.
Dempsey was just unable to slot home after a breakaway attack, but the ball fell kindly for Donovan who slotted into a gaping net from close range.
That proved to be the winner and demoralised Algeria would end the game with 10 men when Yahia was dismissed soon after.