Serbia was the better side at the start of the decisive Group B match, ending the first half 11-9 up. Hungary took control of the game in the second by scoring the first five goals to level 14-14 and then six more to take a commanding lead.
Tunisia also advanced after beating Argentina 25-23, with Kamel Alouine scoring seven goals.
Despite Diego Simonet's six goals, Argentina were no match for Tunisia although they were just a goal down in the final minute of the Group A match. Aymen Toumi scored in the final seconds to secure Tunisia's spot in the quarterfinals.