Landon Donovan scored a last-gasp winner to beat Algeria and put the United States into the last 16 after a pulsating and even match in which both sides created a host of chances to claim victory.
Donovan got the vital winner in the second minute of injury time just as it seemed the US were about to go out of the tournament. Instead, the result meant they finished top of Group C ahead of England on goal difference. Algeria were eliminated.
"I have been on a long journey the last four years. I'm just shocked and so proud of our guys, unbelievable. We're alive, baby," Donovan said after the match. "Clint [Dempsey] made a good run in the middle, the ball fell to me... time kind of stopped. You can't miss from there," he added about his winner.
US coach Bob Bradley was delighted with his team's never-say-die performance. "These guys put a lot into it," he said. "They never quit. We were pushing hard for a goal. It made for a wide open game, but we needed a win."
Algeria's coach, Rabah Saadane, was left to rue missed chances. "In the final moments both teams began to attack but the Americans had the luck today," he said.
The match was only 12 seconds old when the first chance fell to Algeria's Karim Ziani but his volley from outside the penalty area flew just wide of Tim Howard's goal. The North Africans came close again in the sixth minute with another volley, Rafik Djebbour taking advantage of a mistake by defender Jay DeMerit, only to see his shot crash against the bar.
The Americans responded just moments later with a powerful drive by striker Herculez Gomez, which forced goalkeeper Rais Ouheb Mbouli to palm the ball away for a corner.
The United States had a goal disallowed late in their 2-2 draw with Slovenia and were frustrated again when Dempsey's 20th-minute finish from a Gomez pass was ruled offside.
Dempsey threatened again on 57 minutes when a Jozy Altidore cross fell to him near the penalty spot, but his curling shot hit the post.
Seven minutes later the United States pushed forward once more when Benny Feilhaber, who came on at halftime for Gomez, put in a dangerous cross that forced Mbouli into a reflex save with his outstretched leg.
The United States looked the more dangerous side, but the Algerians gave them occasional scares, such as Hassan Yebda's 68th-minute fierce strike that went wide after a flowing counter-attack.
Donovan settled the contest right at the death but there was still time for Algeria's Antar Yahia to be sent off for a second yellow card.
United States (4-4-2): Howard; Bocanegra (Beasley, 81), Cherundolo, Bornstein, DeMerit; Bradley, Dempsey, Edu (Buddle, 64), Donovan; Gomez (Feilhaber, 46), Altidore.
Algeria (4-4-2): M'Bohli; Bougherra, Yahia, Halliche, Belhadj; Lacen, Ziani (Guedioura 69), Yebda, Kadir; Djebbour (Ghezzal 67), Matmour (Saifi 86).
Referee F De Bleeckere (Belgium).