A moment of Ronaldo class and a controversial Adriano goal helped give Brazil a 3-0 win over Ghana on Tuesday but their path to the World Cup quarter-finals was far from smooth.
Ronaldo struck after five minutes but Ghana piled on the pressure and exposed the world champions' defence on several occasions before Adriano broke their hearts, if not their spirits, in first-half injury time.
Midfielder Ze Roberto added the third in the 84th minute when he slipped the Ghanaian offside trap once more.
Ghana ended the match with 10 men, striker Asamoah Gyan sent off in the 81st minute when he collected his second yellow card for a dive.
Brazil, seeking a fourth successive final appearance and a sixth triumph, now face Spain or France, who meet in the last remaining second round game later.
Brazil got the ideal start when Kaka sprung the offside trap with a pass into the path of Ronaldo and the striker bamboozled Ghana goalkeeper Richard Kingston with a quickstep dummy before tucking in his 15th World Cup goal, overhauling the record he shared with Germany's Gerd Mueller.
Ghana, without suspended midfield inspiration Michael Essien, looked in disarray in the first 20 minutes but gradually settled to attack the shaky heart of the Brazilian defence and create a series of chances that had the world champions rattled.
Matthew Amoah should have scored but scuffed his shot in front of goal after 24 minutes and John Mensah then met a corner with a perfect downward header that Brazil keeper Dida somehow kept out with his foot.
Ghana were then stunned on the break with a controversial goal as Kaka fed the overlapping Cafu, making a Brazilian record 19th World Cup finals appearance.
Adriano was well offside at that point but play continued as he had not collected the ball but he was certainly involved, and probably still marginally offside, as he drove into the six-yard box to nudge home his captain's low cross.
The Ghana players protested to no avail as did their Serbian coach Ratomir Dujkovic, who was sent to the stands for his troubles.
The last remaining African side in the competition did well to come out fighting, with Gyan forcing Dida into a good diving save after 69 minutes.