© Getty Images
Despite Hungary seeing much more of the ball, it was Northern Ireland who had the best chance to break the deadlock before half time.
Gergely Rudolf forced Roy Carroll into a smart save midway through the second half before the home side did go in front when Dzsudzsak's corner was headed home by half-time substitute Tamas Priskin in the 75th minute.
Hungary weren't ahead for long, though, as McGinn tapped home from a few yards out after a neat move with Lafferty of Norwich City.
Aberdeen's McGinn turned provider for the 88th-minute winner, drilling across goal where Lafferty bundled home to give Michael O'Neill's men victory over a team that is ranked more than 50 places higher than them in the FIFA rankings.