Updated

The United States stunned top-ranked Spain 2-0 Thursday night on goals by Jozy Altidore and Clint Dempsey, advancing to the Confederations Cup final with one of the Americans' biggest soccer victories.

Altidore scored in the 27th minute and Dempsey added a goal in the 74th as the Americans became the first team to defeat Spain since Romania in November 2006.

Click here to see photos from the game.

The chances of such a U.S. victory seemed slim just a few days ago. The 14th-ranked Americans lost their first two games in the Confederations Cup, an eight-nation World Cup warmup, and were on the verge of elimination.

Now they will play defending champion Brazil or host South Africa on Sunday in its first-ever men's final at a FIFA competition.

Spain, the European champion, had set an international record with 15 straight victories and was trying to stretch its unbeaten streak to 36, breaking the mark set by Brazil from December 1993 to January 1996.

But American goalkeeper Tim Howard came up with several big saves and Altidore got the first goal when he outmuscled Joan Capdevila, his teammate on Spain's Villarreal to beat goalkeeper Iker Casillas. Dempsey scored when he pounced on Landon Donovan's cross, which bounced off the foot of Sergio Ramos.

Midfielder Michael Bradley, the son of U.S. coach Bob Bradley, will miss the final. He received the Americans' third red card of the tournament for a late sliding tackle in the 87th minute.

The U.S. had been 1-7-1 against top-ranked teams, beating Brazil in the 1998 CONCACAF Gold Cup and tying Argentina last summer in an exhibition at Giants Stadium. When the United States upset Brazil, goalkeeper Kasey Keller had an outstanding game, just as Howard did.

The Americans were boosted by the return of captain Carlos Bocanegra, who had been sidelined since injuring a hamstring during a World Cup qualifier on June 6. He played left back instead of central defense.

The United States had lost its three previous matches against Spain, 3-1 in the first round of the 1950 World Cup, 2-0 in a 1992 exhibition at Valladolid and 1-0 in an exhibition on June 4 last year at Santander.