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," Donovan told US television after the match. "We're alive, baby."
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 Karim Ziani but his volley from outside the penalty box flew just wide of Tim Howard's goal.
Algeria came close again in the sixth minute with another volley, Rafik Djebbour taking advantage of a mistake by defender Jay DeMerit to send his shot crashing against the bar.
The Americans responded just moments later with a powerful drive by striker Hercules Gomez forcing keeper Rais Ouheb Mbouli to palm away for a corner.
The United States had a goal disallowed late in their 2-2 draw with Slovenia and were frustrated again when Clint Dempsey's 20th minute finish from a Gomez assist 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 which forced Mbouli to 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 put the United States ahead right at the death and there was still time for Algeria's Antar Yahia to be sent off for a second yellow card.