Defender Maicon produced an astonishing goal out of the blue to set Brazil on their way to a 2-1 win over a stubborn North Korea and spare their blushes after a shockingly bad first-half performance Tuesday.
But there was still time for the North Koreans' Ji Yun-nam to stun the Brazilians, going past two players and crashing home a left-foot drive in the 89th minute to set up a nervy finish for the South Americans.
"They played very defensively and in this kind of game you have to have patience and when you don't get a goal, it gets difficult," Brazil forward Robinho told Brazilian TV.
"But we won deservedly ... now we can lift our heads and look to qualify in the next game."
However, until Maicon's strike, North Korea, making their first World Cup performance for 44 years, had looked capable of pulling off a result to match their famous 1-0 win over Italy in 1966.
Brazil had looked clueless as to how to unlock their defence and the Asian team, gaining in confidence, had looked threatening going forward.
Brazil started brightly enough when Robinho produced a dazzling run with his trademark stepovers in the first minute to set up Kaka but the Real Madrid player took too long to line up his shot and An Yong-hak took it off his feet.
Robinho shot over after working another opening with Kaka but Brazil's play quickly deteriorated.
North Korea's Jong Tae-se had the first shot on target, although it was easily saved by Julio Cesar, and Mun In-guk tried to lob Julio Cesar from near halfway line as the outsiders grew in confidence.
Brazil had placed their creative responsibility on Kaka but he was having a dismal game with passes going completely astray.
They had isolated openings, one when Robinho tested Ri Myong-guk with a shot on the turn and another with an outswinging Maicon shot which the goalkeeper parried away.
The five-times champions committed more men forward after the break and had an excellent chance when they were awarded a free kick on the edge of the area, but Michel Bastos fired his effort metres wide.
But the breakthrough came when Elano slid the ball into the path of Maicon who managed to find the gap between the keeper and the near post from almost on the byline.
Elano added the second when he ran onto Robinho's slide-rule pass and slotted his shot into the far corner.