Italy had initially led 3-1 but Hungary overturned that to take a 5-4 advantage before the Italians pulled clear.
Hosts Greece stunned third-ranked Russia with a 7-4 victory and they now face Australia in the last four.
Antigoni Roumpesi scored two goals in the second period, while Kyriaki Liosi added two more in the third.