Striker David Villa scored in stoppage-time to give Spain a 2-1 victory over Sweden in a scrappy Group D encounter at Euro 2008 on Saturday.
Sweden striker Zlatan Ibrahimovic looked to have earned his side a share of the points with a 34th minute equaliser after Spain had taken a deserved lead on 15 minutes with a clever finish from striker Fernando Torres.
But Villa, who hit a hat-trick in Spain's opening 4-1 rout of Russia, secured the points with a close-range finish on the break in the second minute of stoppage-time.
The result puts 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.
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 into the area.
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 involving Fredrik Ljungberg and Ibrahimovic, although Johan Elmander almost equalised a minute after the Torres goal when he lashed the ball 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. Sweden responded 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 Casillas with an angled shot.
Sweden coach Lars Lagerback took Ibrahimovic off at halftime and replaced the lanky striker, who has been suffering a knee problem, with Markus Rosenberg.
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.