Brazil have qualified for the last 16 with a game to spare after coming from behind to beat ten-man Hungary in New Plymouth.

A late Andreas Pereira penalty settled the outcome of this match, but in truth it turned on the 16th-minute dismissal of Krisztian Tamas - when Hungary were a goal up. Until that point, this eagerly anticipated top-of-the-table clash in Group E had lived up to its billing and looked set to be an open, evenly balanced affair. Hungary were certainly giving as good as they got and had even taken a shock eighth-minute lead through the in-form Bence Mervo.

The goal was a comedy of errors from Brazil, with first defender Lucao misjudging a long ball and then keeper Jean allowing the striker's speculative shot from wide on the right to squirm through his grasp and just over the line. Mervo deserved great credit, though, for being alert enough to capitalise on the initial mistake and audacious enough to go for goal from such an awkward angle. He now has four goals in just two appearances at New Zealand 2015. 

Hungary, though, had just seven minutes to enjoy their lead before a moment of madness cost them dearly. Left-back Krisztian Tamas, already on a yellow card, slid in needlessly and recklessly to foul Gabriel Jesus on the halfway line, and the outcome was inevitable. That left the Europeans to hang on grimly for the remainder of the game, and initially it seemed like they might just prove capable of doing that.

So frustrated were Brazil, in fact, that coach Rogerio Micale made a double half-time substitution, bringing on Jaja and Andreas Pereira in an attempt to change the course of the game. The latter in particular made a major impact, and it was his 50th-minute corner that led to Brazil's equaliser. Captain Danilo was the man to meet it, climbing majestically to bullet an unstoppable header high beyond the helpless Gyorgy Szekely.

Still, Hungary refused to fold, but just as they appeared on course to secure a hard-fought point, a late penalty undid all their hard work. Gabriel Jesus earned it, showing great footwork to twist away from a couple of changes before drawing a lunging challenge by Szekely. It was then left to Pereira to keep his cool and seal the points with the calmest of spot-kicks, beating the Hungary keeper low to his right with a measured side-foot finish.

Brazil can now look forward to the knockout phase, while Hungary must take at least a point against Nigeria in their final Group E match to be sure of progressing.