Barcelona new boy Neymar maintained his record of scoring in each match at the tournament so far by grabbing his team's second goal as the hosts forged ahead for a second time after Dante's opener had been cancelled out by Emanuele Giaccherini.
Fred then netted twice, with Giorgio Chiellini on target in between, as the hosts extended their perfect start to the competition to head into the knockout stage - alongside the Azzurri - full of momentum.
Both teams headed into the game having already assured their places in the semi-finals, having beaten Mexico and Japan in their previous outings, and were effectively playing for the right to avoid in-form world and European champions Spain in the next round.
The game looked set to be goalless at the break but the deadlock was finally broken in first-half stoppage time, defender Dante pouncing from close range after Fred's header had been brilliantly parried by Italy goalkeeper Gianluigi Buffon.
Giaccherini, teed up by Mario Balotelli, rounded off a swift counter-attack to get Italy back on level terms within six minutes of the restart.
Parity lasted less than four minutes, however, before Neymar placed a fine free-kick into the top corner, leaving Buffon stranded.
Fluminense forward Fred then extended Brazil's lead with a neat finish into the top-left corner from Marcelo's pass midway through the second period.
Chiellini gave Italy hope of a comeback when he converted Alberto Aquilani's assist five minutes later, and they were within a whisker of making it 3-3 10 minutes from time when Cristian Maggio's header smashed against the bar.
But the equaliser was not forthcoming and Fred restored the 2014 World Cup hosts' two-goal cushion in the 88th minute with another close-range strike after Buffon had denied Marcelo.