After scores were locked 1-1 at half time, Patrick Vieira, the hero in France’s match against Togo in Cologne, put his side ahead in the 83rd minute when he headed in at the far post from a Zinedine Zidane free-kick.
Then, the French captain himself sealed the match in stoppage time when he went one on one with Real Madrid team mate and Spanish keeper Iker Casillas, beating him with a well placed shot from inside the box.
In the first half, Spain were awarded a penalty in the 27th minute when Juventus defender Lilian Thuram cluttered into the back of Spain's Pablo Ibanez, with Italian referee Roberto Rosetti having no hesitation in pointing to the spot.
24 year old striker David Villa, who scored from the spot in his side’s opening match against Ukraine, stepped up to take the penalty and made no mistake when he snuck his shot inside the left post, giving a diving Fabien Barthez no chance.
However with just four minutes remaining in the first half Vieira released midfielder Frank Ribery with a fantastic pass, and the Marseilles player they call 'scarface' rounded keeper Casillas before finishing with his left foot to score his first ever goal for his national team.
A good match with a fast tempo continued in the second half, but with extra time looking likely a cynical and needless foul by Barcelona player Puyol on striker Thierry Henry led to a yellow card for the defender and the free kick that led to Vieira's goal.
Patrick Vieira has scored two
goals in two games for France
Zidane floated the ball into the box where Spanish midfielder Xavi Alonso headed the ball to the far post where Vieira then headed towards goal, with the ball hitting Real Madrid defender Sergio Ramos on the way into the back of the net.
Earlier, Spain engineered a tricky free kick in the 9th minute which Getafe player Pernia hit with his left foot to bend it close to goal, although French keeper Barthez looked to have it covered.
In the 23rd minute, midfielder Zidane sent a ball wide to Henry who put in a perfect cross which a sliding Ribery missed at the near post, with a lunging Vieira only able to get a big toe on when right in front of goal.
Zidane put Olympique midfielder Florent Malouda through on 52 minutes with the Lyon player attempting to chip Casillas, but the Real Madrid keeper dived acrobatically to make the save.
For Spain, it is yet another heartbreaking exit from a major tournament, when it was looking like their time to shine, meaning the dreaded tag of 'underachievers' will stick with them until they can prove otherwise.
David Villa scored for Spain, but
it wasn't enough
Coach Luis Aragones was confident that his side would progress before the second round match, but Spain exit the World Cup Finals at the same stage they did four years ago.
France now go on to a dream quarter final with Brazil – a replay of the 1998 World Cup final match in which France became World Champions, winning 3-0 in Paris.
The architect for France in that match was none other than Zinedine Zidane, the current French captain who is slowly finding form along with his team, ahead of what should be a great match against the defending World Champions in Frankfurt.