Ronaldo moved alongside the former West Germany [ Images ] striker when he grabbed his second goal of the game for the champions in the 81st minute.
Second-half goals from Juninho Pernambucano, Gilberto and Ronaldo again allowed Brazil to finish the group with maximum points and complete their 10th successive win at the World Cup finals.
Brazil face Ghana in the last 16 while Japan, with one point, were knocked out.
Ronaldo kept his place but coach Carlos Alberto Parreira made five other changes.
For the first 20 minutes, Brazil's football flowed for the first time in the tournament as they sliced through the Japan defence.
Only goalkeeper Yoshikatsu Kawaguchi stood between the rampant champions and a significant lead.
Kawaguchi turned away two efforts from Ronaldo and one each from Robinho, Kaka [ Images ] and Juninho.
But Brazil left gaps at the back and Japan took advantage when Alex slipped the ball inside to Tamada, who fired past Dida with a first-time shot on the turn.
It was the first goal Brazil had conceded in seven internationals, the last being against Bolivia last October.
Brazil were knocked out of their stride but levelled out of the blue.
Ronaldinho's [ Images ] diagonal pass found Cicinho, he headed across the goal and the unmarked Ronaldo headed home.
Juninho put Brazil ahead with a dipping 30-metre effort which went through Kawaguchi's hands in the 53rd minute.
In the 59th minute, Ronaldinho produced a slide-rule pass for Gilberto to break down the left and place the third past Kawaguchi.
Ronaldo made it 4-1 when he swivelled before curling in a shot from the edge of the box.