Fred fired in from close range just after the hour-mark at the Arena Fonte Nova before adding another two minutes from time after Marcelo's shot was kept out by Italy goalkeeper Gianluigi Buffon.

After the match, the Fluminense striker said he had benefited from finally overcoming a fractured rib.

"It is the game in which I have felt most comfortable since the tournament began. It's a credit to the medical staff who have helped me to recover. I'm happy to have played such a decisive part in the victory," Fred said.

Bayern Munich defender Dante had given Brazil the lead on the stroke of half-time by bundling in at the far post following Buffon's reflex save from a Fred header. Dante had been introduced 10 minutes earlier as a substitute for Chelsea's David Luiz, who was forced off with an injured right thigh.

Emanuele Giaccherini equalised after a cunning Mario Balotelli backheel before Fred and then Neymar -- the latter with a sumptuous free-kick -- gave Brazil a 3-1 advantage.

Giorgio Chiellini reduced the deficit with a low finish following Alberto Aquilani's cross before Fred's predatory instincts put the result beyond doubt.

At the Mineirao Stadium, Hernandez broke the 0-0 first-half deadlock by heading in twice within 12 minutes.

In a frenetic finish, Shinji Okazaki gave Japan hope five minutes from time, tapping in after Yasohito's deft one-touch pass from a Shinji Kagawa cross.

Hernandez missed the chance for a hat-trick when his spot-kick was kept out by Eiji Kawashima and he then sent the rebound crashing off the crossbar.

Mexico and Japan are eliminated from the tournament while Brazil and Italy's semifinal opponents will be decided by Sunday's Group B fixtures between Nigeria-Spain and Uruguay-Tahiti.