Spain went in front in the 15th minute when David Silva passed the ball to Fernando Torres who scored past keeper Andreas Isaksson.
Sweden came right back and had a couple of opportunities to equalize, in the 34th minute Zlatan Ibrahimovic latched onto a cross from Fredrik Stoor and slid his shot past Iker Casillas to make it 1-1.
Two minutes into stoppage time, Villa latched onto a long ball from the back and he put a good touch on it to slip it by Isaksson, claiming three points in dramatic style.