It was a star performance from Neymar, who in his debut World Cup has now scored four goals.
The Barcelona superstar opened the scoring in the 17th minute with a deft touch to finish a Luis Gustavo cross.
FINAL GROUP A STANDINGS
Brazil: Played 3, Won 2, Drawn 1 Goals For 7, Goals Against 2, Points 7
Mexico: Played 3, Won 2, Drawn 1, GF 4, GA 1 Points 7
Croatia: Played 3, Won 1, Lost 2, GF 6, GA 6, Pts 3
Cameroon: Played 3, Lost 3, GF 1, GA 9, Points 0
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
Yet the favourites found it difficult to break through the defence line of Cameroon that had conceded five goals in previous two games against Mexico and Croatia.
Cameroon looked a much better attacking side then they have done so earlier and created quite a few problems for a shaky Brazilian defence.
Neymar, though, ended a good spell of play from Cameroon with an excellent touch to guide Luis Gustavo's cross into the net.
Barcelona right-back Dani Alves was a weak link, allowing the Cameroon wingers to constantly venture into the Brazilian final third and put in dangerous crosses.
Alves was again beaten on the right that led to Matip stabbing in Cameroon's equaliser from close range.
Neymar grabbed his brace as he latched on to a David Luiz clearance and twisted and turned to beat couple of Cameroon defenders and bulleted his right-foot shot giving the keeper no chance.
To their credit, Cameroon refused to give up and harried the Brazilian defence and could have so easily scored another goal.
In the second half, it was all one-way traffic. Fred found himself at the end of a David Luiz cross and headed the ball in for Brazil's third.
The goal seemed to take the gas out of Cameroon who after that barely caused Brazil any problems at the back and let the opponents run the show.
Neymar and Oscar saw a lot of the ball and their one touch play was excellent to see.
Brazil coach Luiz Felipe Scolari took Neymar out taking the sting out of the game.
Substitute Fernandinho finished off a beautiful team move to make sure that Brazil continued to have a better goal difference than Mexico to finish top of the group.