He opened the scoring off a low cross by midfielder Luiz Gustavo in the 17th, deftly side-footing the ball home from close range, then restored the lead with a low right-foot strike from the top of the penalty area in the 35th after a pass by left-back Marcelo.
"I have the responsibility to go out there and help my teammates," Neymar said. "We all did well today and got the result that we needed."
Fred found the net in the 49th and the substitute Fernandinho struck in the 84th minute.
"I liked how the team played," Brazil coach Luiz Felipe Scolari said. "There were some highs and lows, but in general we improved a little bit more. We are progressing match after match and that's important."
Brazil finished Group A with seven points after a 0-0 draw with Mexico and two wins. They ended with the same points as Mexico, but had a better goal difference. The Mexicans eliminated Croatia with a 3-1 win in Recife.
"We knew we had to do better today," Brazil striker Hulk said. "We had to play better and we did."
Playing in their 100th World Cup match, Brazil needed at least a draw to advance. Elimination in the group stage would have been unthinkable for the five-time world champions playing at home. The only team to play in all 20 World Cups, Brazil have advanced to the second round in every tournament since 1970.
Boosted by a crowd of nearly 69,112 at the Estadio Nacional in the nation's capital, Brazil began the match pressuring Cameroon and created many scoring chances early. But the African team picked up the pace and were able to keep the hosts from threatening too much.
Despite playing without Samuel Eto'o because of a lingering right knee injury, Cameroon had a few good chances, even when the match was level in the first half.
"The first half was not so bad, but we need to focus for 90 minutes, and this is not the first time that this happened," Cameroon coach Volker Finke said.
It was Neymar who got on the board first, neatly finding the net after Gustavo stole the ball on the left flank and sent a low cross into the area.
Cameroon equalised after a nice run by Allan Nyom ended with Matip's goal, but Neymar again showed he is carrying the hopes of the entire nation, running towards the area and then moving to his right in front of a couple of defenders before firing a low shot into the net.
The 22-year-old Barcelona striker had already been decisive in the 3-1 opening win over Croatia, when he also scored twice while Brazil were struggling.
Brazil improved in the second half and Fred, who had been loudly criticised for his lacklustre performances, got his first goal of the tournament with a header from close range.
Fernandinho, who replaced Paulinho in the second half, poked in from short range after good leadup work from Oscar and Fred.
Cameroon, who haven't advanced to the second round since becoming the first African nation to reach the World Cup quarter-finals in 1990, likely saw Eto'o playing in his final World Cup.
The 33-year-old striker, in his fourth World Cup, is the team's all-time leading scorer.