Spain 2 Sweden 1: An injury time strike from David Villa all but secured Spain's passage into the knock-out stages of Euro 2008 and left Sweden with it all to do in Group C, despite their opening win against Greece.
Sweden looked to have a point in the bag after Zlatan Ibrahimovic's goal cancelled out Fernando Torres' first half opener but Villa, who scored a hat-trick against Russia days ago, pounced in the 92nd minute to coolly send his side into the last eight.
It was no more than Spain deserved after they dominated the second half against a side lost without Ibrahimovic, who was forced off at half-time through injury.
The result puts Group D leaders Spain close to a place in the quarter-finals with six points from two games, though Sweden are still in the race on three points. Russia and Greece, who have yet to register a point, play this evening.
Spain coach Luis Aragones told a news conference: "Apart from 15 minutes when we got infected by playing the long-ball game, I think we were the better side.
"We were definitely the better side when we started playing the way we know with the ball."
As for the dramatic finish, he added: "Villa scored an incredible goal."
Villa played down his contribution to Spain's campaign at Euro 2008, saying: "The important thing is that we've got six points from two games.
"It's great that I've kept scoring too. But more important is that the side is still winning."
Sweden coach Lars Lagerback struggled with the disappointment at such a last-gasp defeat, saying: "This is a bitter way to lose, with all respect to Spain.
"We were beaten by a goal out of nothing."
Spain took the initiative early on at the Tivoli Neu stadium with Xavi marshalling the midfield and Torres giving fullback Mikael Nilsson some early problems with his surging runs.
It came as little surprise when Spain took the lead, Torres getting in front of his man and steering the ball in with the sole of his boot after David Silva had clipped the ball into the area following a corner.
Largely deprived of possession, Sweden had to rely on isolated counter-attacks through Freddie Ljungberg and Ibrahimovic, although Johan Elmander almost equalised a minute after Torres's goal when he fired into the side netting.
Spain suffered a major setback when experienced centre-back Carles Puyol was forced off through injury and replaced by Raul Albiol midway through the half.
The Spanish Federation said he would undergo tests on Sunday to assess the damage.
Sweden responded to Spain's loss of their experienced centre back by upping the pressure on the back four.
The tactic paid off 11 minutes before the break when Ibrahimovic controlled an Elmander cross at the second attempt, turned past fullback Sergio Ramos and beat keeper Iker Casillas with an angled shot.
Lagerback took Ibrahimovic off at halftime and replaced the lanky striker, who has been suffering a knee problem, with Markus Rosenberg.
After the break, David Silva and Torres were both denied during a goalmouth scramble and keeper Andreas Isaksson turned a rasping drive from Marcos Senna around the post soon after.
A draw was very much on the cards until Villa's late strike