Julio Cesar was Brazil's hero as they avoided becoming the first host nation since Italy in 1990 to go out of the World Cup on penalties when they beat Chile in the first round of 16 game in Belo Horizonte.
QPR goalkeeper Cesar, who played just eight games for the Championship side last season, saved from Mauricio Pinilla and Alexis Sanchez before Gonzalo Jara hit the post with the vital final spot kick.
Just moments before the shootout, Pinilla was inches away from sending Chile into the quarter-finals when he played a neat one-two with Alexis Sanchez before thundering an effort against the bar from 20 yards.
In normal time, Luiz opened the scoring on 18 minutes when he bundled home a corner from close range for his first international goal. The lead lasted just 14 minutes before Alexis Sanchez latched onto a pass from Eduardo Vargas before side-footing past Julio Cesar.
How the shootout happened...
1-0 Luiz - scored
1-0 Pinilla - saved
1-0 Willian - missed
1-0 Sanchez - saved
2-0 Marcelo - scored
2-1 Aranguiz - scored
2-1 Hulk - saved
2-2 Diaz - scored
3-2 Neymar - scored
3-2 Jara - missed
But it was Howard Webb who provided the biggest talking point of the match when, on 55 minutes, the English referee disallowed Hulks goal after he appeared to bring down a long ball with his arm before scoring - with replays suggesting it was the correct decision.
Both Neymar and Sanchez went close late on but neither side could find the breakthrough to avoid extra time.
Webb had also turned down a penalty claim by Hulk, as well as one by Chile's Eduardo Vargas, while Brazil coach Luiz Felipe Scolari was furious he did not take a tougher line on some forceful challenges on Neymar.
It was Neymar who was the man at the centre of most of the action for Brazil in the first half but it was Marcelo who shone first with a skilful turn on the edge of the box that fooled his marker and earned the Real Madrid full-back space to send a low shot just a yard past the post.
Chile looked threatening on the break but Brazil dominated possession and took the lead in the 18th minute when Neymar's corner was headed on by Thiago Silva and then diverted into the net. Luiz was credited with the goal but replays appeared to suggest it was an own goal.
That should have been the signal for Brazil to assume total control but instead Chile pounced on a shoddy mistake to equalise.
After Hulk messed up a return to Marcelo's throw-in by their own touchline, Vargas snapped up the ball and found Sanchez who neatly slotted home his second goal of the tournament.
Neymar continued to look Brazil's biggest hope and his header from Oscar's cross bounced off a defender's arm, which diverted the angle just enough to take it past the post.
Oscar found his range and his brilliant cross-field pass found Neymar again threatening but he dallied; Chile then scrambled the ball clear but it ricocheted off Fred and just over the bar.
A dipping strike from distance by Dani Alves was turned over by Claudio Bravo, before Brazil's out-of-form striker Fred made perhaps the most embarrassing miss of the World Cup so far, mis-hitting the ball hopelessly just before the break.
But Brazil always looked vulnerable and another error, by Luiz Gustavo this time, saw Sanchez threaten again but Luiz managed to hurl himself in to block for a corner.
The second half saw Brazil frustrated by nerves and by Webb, while Scolari's decision to push Neymar further forward saw him drop out of the game.
Then came the controversy. Brazil believed they had gone in front after Marcelo's long ball was brought down by Hulk, who then sliced it into the bottom corner, but it was wiped off by an assistant's flag who said the striker controlled it with upper arm. It was a controversial decision and to rub salt in the wound Webb booked him.
Chile then began to assume an air of superiority while Brazil looked worried, and were grateful to wonderful save by Julio Cesar to turn aside what looked a certain goal for the excellent Charles Aranguiz.
Former Manchester City striker Jo came on for Fred and looked destined to score straight away but somehow missed, then Neymar's flicked header was straight at Bravo.
The Chile keeper stood up strong again after brilliant work by Hulk, but it was Brazil who were relieved to take the game to extra time.
Oscar had a half-chance with a header, Bravo kept out Hulk but it was Chile who nearly snatched it at the death only for Pinilla's blistering strike crashed back off the crossbar.
Penalties followed, and Julio Cesar saved from both Mauricio Pinilla and Alexis Sanchez either side of a Willian miss to put Brazil in charge, but Claudio Bravo then blocked Hulk's effort.
However, after Neymar had converted, Jara hit the post with the final penalty to send the hosts through.