Late goals in each half from Imre Szabics and Gergely Rudolf sent Hungary into ecstasy as they ended a miserable run of results against Sweden and revived their chances of qualifying from Group E.
Szabics' cool finish late in the first half and a stunning winner from Rudolf a minute from the end took the hosts past a shell-shocked Sweden side who equalised on the hour through Christian Wilhelmsson, but were ultimately punished for their profligate finishing.
Hungary might have thought their luck was out in the 19th minute when Oscar Wendt handled the ball in the penalty area after a dangerous cross from Rudolf. To the home crowd's dismay, captain Tamás Hajnal's shot clattered back off Andreas Isaksson's crossbar.
Sweden then hit the woodwork when Zlatan Ibrahimović twisted past Zsolt Korcsmár in the area in the 27th minute but his left-footed shoot came back off Gábor Király's left post. Sándor Egervári's side broke the deadlock a minute before half-time, Rudolf sliding a pass through the Swedish defence for Szabics to clip past Isaksson.
The visitors menaced Hungary after the restart and it was no surprise when the equaliser arrived. A delightful move that began with a powerful Johan Elmander run through the middle and a one-two with Ibrahimović ended with the Galatasaray SK striker squaring the ball across Király for Wilhelmsson to side-foot in.
The hosts continued to live dangerously as Erik Hamrén's men hunted for the winner. Ibrahimović almost got dangerously close to a Wilhelmsson cross on 72 minutes, and Kim Källström then found space on the edge of the area, but his drive shaved the post on its way wide.
With time nearly up, substitute Tamás Priskin jinked into space on the right and centred for the impressive Rudolf to blast a dramatic winner. The two sides are now level on 15 points behind the Netherlands, though Sweden have a game in hand.