An improved Greece side were felled by a late Spanish winner in Salzburg as the reigning European champions ended Euro 2008 without a point.
With their qualification already secured, Spain changed ten of their starting eleven, while Greece, who were knocked out after losing to Russia on Saturday, were playing for pride.
Spain started the match looking like the side with the least to play for. The passing and invention was there from Cesc Fabregas and Andres Iniesta, but no great urgency was shown.
Sergio Garcia was given a number of half-chances but his ability to turn those opportunities into goals was noticeably weaker than either that of David Villa or Fernando Torres.
Instead it was left to long-range efforts from Xabi Alonso, who curled two low shots just wide of Antonios Nikopolidis' left-hand post and saw a stunning strike from inside his own half miss the goal by a few inches with the Greek keeper beaten.
The lethargy Spain showed in attack finally cost them when Greece opened the scoring three minutes before half-time.
A number of dangerous set-pieces had already been sent in by Angelos Basinas and the ever-dangerous Giorgos Karagounis, but Spain persisted in giving away needless free-kicks inside their own half.
Inevitably it was a Karagounis set-piece that led to the goal, the Panathinaikos midfielder curling a cross in from the left and finding Angelos Charisteas in plenty of space to power a header past Jose Reina.
The Spaniards continued to look toothless inside the penalty area and only a wicked blast from Alonso, whose swerving drive beat Nikopolidis but hit the inside of the post after 54 minutes, came close to the Greek goal in the first 15 minutes of the second half.
Then, just after Dimitrios Salpingidis had mis-hit two good shooting chances in two minutes, Ruben De la Red almost broke the net to bring Spain level.
A long ball from Fabregas was knocked down by Daniel Guiza into the path of De la Red. The Real Madrid midfielder struck a vicious drive from eight yards that hit Nikopolidis' arm but still tore into the back of the net.
Greece, rather than Spain, found themselves in need of some urgency and Charisteas produced it, rounding Reina minutes after the Spanish equaliser and shooting from a tight angle, but only finding the outside of the post.
For all the effort Greece put in, the quality of Spain began to show and a second goal in the 88th minute ensured that they finished the group stage on a high.
A deep cross from Garcia found Guiza in enough space to place a header beyond Nikopolidis and high into the net, giving them the perfect boost before they face Italy in the quarter-finals.