Brazil survived a late Japan fightback to clinch a 2-2 draw and make the Confederations Cup semi-finals.
Ronaldinho scored as Brazil held on for a draw and a semi-final spot
Brazil went ahead through Robinho on 10 minutes before Japan, coached by Brazilian legend Zico, levelled with a 30m drive from Shunsuke Nakamura.
Ronaldinho restored the lead in the 32nd minute before substitute Masashi Oguro fired home with two minutes left.
Brazil, who secured second place in Group B behind Mexico, will now face host nation Germany on Saturday.