Brazil squeezed through to the quarter-finals of the World Cup after coming within a whisker of going out against an accomplished Chile side.
Neymar's penalty in a shootout proved decisive when Chile's former Nottingham Forest, West Brom and Brighton defender Gonzalo Jara smashed the final spot-kick against the post.
The win keeps alive Brazil's dreams of winning a World Cup on home soil - and their record of not losing a competitive match at home since 1975.
Chile had taken Brazil all the way in Belo Horizonte, dominating for long spells of the second half and nearly snatching victory at the death through Mauricio Pinilla's strike which hit the crossbar.
Brazil had taken the lead through a goal awarded to David Luiz - although it appeared to come off a Chile player - before Chile netted a deserved equaliser through Alexis Sanchez.
"It was complicated," Brazil goalkeeper Julio Cesar said."The pressure of representing Brazil and playing at home is really great. We played well in the first half, but after Chile equalised they got into the game."
Brazil's win also saved English referee Howard Webb from becoming the country's public enemy number one after he found himself at the centre of huge controversy when he disallowed a goal by Brazil forward Hulk for handball.
If the hosts had enjoyed the rub of the green from officials in previous matches - something that had been flagged up by Chile - there was no danger of such an accusation being made against Webb.
He 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 Marcelo 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 - claimed by Luiz though probably an own goal.
Neymar's corner was headed on by Thiago Silva and it initially looked as though former Chelsea defender Luiz had finished at the far post but replays appeared to show it went in off Jara.
That should have been the signal for Brazil to assume total control but instead Chile pounced on a shoddy mistake to equalise.
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 just 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 crossfield pass found Neymar again threatening but he dallied, Chile 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.
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 chalked 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 for a wonderful save by Julio Cesar who turned 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 goalkeeper 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 and Bravo kept out Hulk but it was Chile who nearly snatched it at the death when Pinilla's blistering strike crashed back off the crossbar.
"It's at time like this you get your support from friends and team-mates and thanks to Julio who made great saves," said Hulk, who missed for Brazil in the shootout
"We ran till the end, God willing we will go to the end and make the final. We suffered but we made it. We knew this would be a very hard game, it went to extra time but even with cramp we ran till the end."
Why are you making commenting on The Herald only available to subscribers?
It should have been a safe space for informed debate, somewhere for readers to discuss issues around the biggest stories of the day, but all too often the below the line comments on most websites have become bogged down by off-topic discussions and abuse.
heraldscotland.com is tackling this problem by allowing only subscribers to comment.
We are doing this to improve the experience for our loyal readers and we believe it will reduce the ability of trolls and troublemakers, who occasionally find their way onto our site, to abuse our journalists and readers. We also hope it will help the comments section fulfil its promise as a part of Scotland's conversation with itself.
We are lucky at The Herald. We are read by an informed, educated readership who can add their knowledge and insights to our stories.
That is invaluable.
We are making the subscriber-only change to support our valued readers, who tell us they don't want the site cluttered up with irrelevant comments, untruths and abuse.
In the past, the journalist’s job was to collect and distribute information to the audience. Technology means that readers can shape a discussion. We look forward to hearing from you on heraldscotland.com
Comments & Moderation
Readers’ comments: You are personally liable for the content of any comments you upload to this website, so please act responsibly. We do not pre-moderate or monitor readers’ comments appearing on our websites, but we do post-moderate in response to complaints we receive or otherwise when a potential problem comes to our attention. You can make a complaint by using the ‘report this post’ link . We may then apply our discretion under the user terms to amend or delete comments.
Post moderation is undertaken full-time 9am-6pm on weekdays, and on a part-time basis outwith those hours.
Read the rules hereComments are closed on this article