Spain led through Fernando Torres' goal on the quarter-hour mark before Zlatan Ibrahimovic grabbed the equalizer 11 minutes before halftime.
In stoppage time, Villa scored his fourth goal in two matches to help Spain claim their second successive win in Group D.
Spain are on top of their group with six points, three ahead of second-placed Sweden.
Russia and Greece, who both suffered defeats in their EURO opener, meet later on Saturday.
Torres put Spain ahead after 15 minutes when he stretched his leg to poke David Silva's superb chip past Sweden keeper Andreas Isaksson.
Johan Elmander could have immediately replied when he was released by Henrik Larsson's pass inside the area but his shot hit the side netting.
Inter Milan's in-form striker Ibrahimovic drew Sweden level in the 34th minute after being helped by some poor marking.
With his back to the goal, Ibrahimovic controlled Fredrik Stoor's cross from the right, shrugged off a tamed challenge from Sergio Ramos before sending a low shot into the net.
Spain keeper Iker Casillas got a hand to it but failed to prevent the ball from crossing the goal-line.
Sweden were unfortunate to lose Ibrahimovic in the second-half due to injury. He made way for Markus Rosenberg.
Villa sealed Spain's victory two minutes into injury time.
He latched onto Joan Capdevila's long ball upfield, slightly touched the ball between Petter Hansson's legs before slotting home.