Hungary took the lead after just one minute when Matteo Gentili shoved Krisztian Nemeth in the penalty area: skipper Vladimir Koman converted the resultant penalty.
Italy were reduced to 10 men in the 71st minute - Gentili seeing red for a second bookable offence - and their prospects looked bleak.
But despite this numerical disadvantage, defender Antonio Mazzotta expertly finished Giacomo Bonaventura’s precision pass with eight minutes remaining.
However, before the full-time whistle there was more drama as Francesco Bini picked up two yellow cards in the space of four minutes while Hungary's Adrian Szekeres saw red for an elbow on Mattia Mustachio.
As tempers boiled over, both coaches - Francesco Rocca and Sandor Egervari - were sent to the stands for dissent.
Nemeth restored Hungary's lead in the 112th minute but within 60 seconds Bonaventura raced towards goal and unleashed an unstoppable equaliser.
Italy were reduced to eight men when Michelangelo Albertazzi got a second caution and Nemeth netted his second to secure victory.