Cameroon defender Joel Matip silenced the boisterous home crowd with a 26th minute equaliser.
But the sea of yellow and green -- Brazilian colours -- were again sent into raptures after a brilliant individual effort from Neymar in the 35th minute.
Fred, who has received a lot of criticism for his performance in the previous two matches, scored his first goal of the tournament in the 49th minute while Manchester City midfielder Fernandinho sealed Brazil's top spot in the 84th minute.
Brazil will take on Chile, who lost 0-2 to the Netherlands earlier in the day, at Belo Horizonte Saturday.
Mexico, who beat Croatia 3-1, will take on the Dutch in the other last-16 encounter
Earlier, Brazil got out off the blocks quickly and created a few good chances early on against a Cameroonian side that had nothing to lose.
Neymar scored two goals in this match to lead the race for the Golden Boot