Rob Earnshaw earned Wales their first away win in 18 months as he poached a late winner in a stormy encounter.
Earnshaw seized on a bad clearance to fire low past goalkeeper Gabor Babos.
Krisztian Kenesei's penalty put Hungary ahead after Danny Gabbidon's foul but Jason Koumas curled in a free-kick to equalise with his first Wales goal.
Some fierce tackles flew in near the end and Robbie Savage had to be led away from a confrontation with Hungary boss Lothar Matthaus at full-time.
Wales, already without 10 first-choice players, received another blow before the match when skipper Gary Speed was ruled out with a stomach bug.
Both sides had a youthful look about them, but Hungary striker Sandor Torghelle belied his years by giving the visiting defence a difficult opening 10 minutes.
Wales appeared to have weathered the storm, but on 18 minutes German referee Florian Meyer awarded Hungary a penalty when Krisztian Lisztes tumbled over the heel of Danny Gabbidon - playing out of position at right-back.
18 mins: Krisztian Kenesei's penalty puts Hungary ahead
20 mins: Koumas equalises with a fierce free-kick
81 mins: Earnshaw pounces for the late Welsh winner
Kenesei, who plays his club football in China for Kouan, calmly converted the spot kick to Paul Jones' right.
Wales hit back to level within two minutes after a foul on Earnshaw, Koumas stepping up to strike the 25-yard free-kick past Babos for his first international goal in nine appearances.
Wales debutant Ben Thatcher, a former England Under-21 player allowed to switch under new Fifa rules, was looking the part at left-back.
The Leicester City player made one vital first-half interception, but some over-zealous tackling did earn Thatcher a booking on the half-hour mark.
Gareth Taylor had a golden opportunity to win it for Wales with 12 minutes remaining, but just failed to get a touch at the near post to an accurate cross.
Yet it hardly mattered three minutes later, when Earnshaw seized on Zsolt Low's horrendous sliced clearance and kept his head to fire low past Babos' right.
After Earnshaw's seventh goal in 11 internationals the game sparked into life, as Hungary poured forward in search of a late equaliser.
It was a frantic last period and Hungary's frustration was clear to see as tackles flew in late and players tussled on and off the ball.
Gabbidon survived a penalty appeal that looked more worthy than the one given against him in the first half, while replacement keeper Danny Coyne pulled off a fine save from Gera's blistering low shot.
The niggly game ended on a sour note, when Robbie Savage and Hungary coach Lothar Matthaus had to be pulled apart after the final whistle.
Hungary: Babos, Komlosi (Dveri 88), Low (Bodor 88), Bodnar, Stark, Zoltan Peto, Molnar (Bojte 80), Lisztes (Toth 52), Kenesei (Szabics 45), Gera, Torghelle (Sebok 70).
Subs not used: Szucs.
Booked: Lisztes, Torghelle, Zoltan Peto, Szabics, Bodnar.
Wales: Paul Jones (Coyne 45), Melville, Gabbidon, Page, Thatcher (Edwards 54), Robinson (Fletcher 89), Savage, Koumas, Vaughan (Gareth Roberts 66), Earnshaw, Taylor.
Subs not used: Barnard, Symons, Collins, Neil Roberts, Margetson.
Referee: Florian Meyer (Germany).