World champions Brazil survived a late Japan fightback to claim a nail-biting 2-2 draw on Wednesday and make it safely through to the Confederations Cup semi-finals.
Brazil took an early lead through Robinho before Japan struck back with a stunning 30-metre drive from Shunsuke Nakamura.
Ronaldinho restored the Brazilian lead in the 32nd minute and they were seemingly on their way to a comfortable enough win before substitute Masashi Oguro fired in on the rebound with two minutes to go.
Japan roared forward and Marcos had to make a point-blank save from Oguro in injury-time to secure the draw Brazil needed to reach the semi-finals as runners-up in Group B behind Mexico, who drew 0-0 with Greece in the other match on Wednesday.
Brazil go on to face host nation Germany in the first semi-final in Nuremberg on Saturday.