Striker Fred scored early in the second half to help Brazil defeat Serbia 1-0 in its final warm-up before the World Cup on Friday.
Brazil was struggling and fans were jeering the team when Fred found the net from inside the area in the 58th minute at a nearly packed Morumbi Stadium. He chested down a cross by Thiago Silva and hit a right footed shot as he fell in between two Serbian defenders.
Brazil coach Luiz Felipe Scolari used the same team that is expected to play in the opener against Croatia on Thursday.
"It was a good match, a good test," Scolari said. "There were some difficulties here and there, but the team is improving and is on the right track for the opener."
Nearly 70,000 people attended the game at the Morumbi for the final warm-up, more than the 61,000 expected for the opening match, which will also be played in Sao Paulo.
Brazil will start the World Cup having won 15 of its last 16 matches, but it gave a disappointing performance before its first match.
The Brazilian squad had difficulties creating significant scoring chances and faced some dangerous Serbian counter attacks, prompting loud jeers by the crowd several times during the match. Brazil had also struggled in the warm-up against Panama on Tuesday until Neymar broke the deadlock by scoring from a free kick in the 25th minute.
"It's normal, it happens when the team is not playing well," Scolari said. "But the players know this, they know that when things are not going right some of the fans will not be happy. But we have to thank them, they were patient most of the time and they helped us get the victory. We hope that will be the case again in the match next week."
The fans at the Morumbi were chanting the name of striker Luis Fabiano, Brazil's starter in the 2010 World Cup, just before Fred broke through the Serbian defense to get the winner.
Striker Hulk had a goal disallowed because of offside in the 75th.
Brazilians complained early on after a few rugged fouls by the Serbs, including one on Neymar just seconds into the match. The Barcelona striker, who scored a goal and set up two others against Panama, had a lackluster performance on Friday and was substituted near the end of the match.
"It was tough to create play, there wasn't a lot of space," Neymar said. "But we have to get used to that, we have to find ways to deal with that. I think for the opener we will be OK."
Brazil will likely begin the World Cup with the same team that won last year's Confederations Cup at home.
Fans packed the Morumbi even though it rained hard for most of the day and traffic remained chaotic across the city because of a strike by operators of subway and overland trains.