Rio Olympics 2016: Thiago Braz da Silva wins Brazil's second gold medal of Games
Brazil's Thiago Braz da Silva set an Olympic record of 6.03m to win a shock gold in the men's pole vault in Rio.
Defending champion Renaud Lavillenie of France looked on course to retain his title after clearing a height of 5.98m.
Da Silva failed in his first attempt at 6.03m but went clear with his second to win Brazil's second gold of the Games.
"Incredible," said the 22-year-old champion. "My first time over six metres. My home town wanted me to win."
Lauvillenie, who was booed by the partisan crowd, took silver, but said he was "disturbed" by the "nastiness" of the atmosphere.
American Sam Kendricks sealed bronze with 5.85m.
"The crowd were cheering me too much," added Da Silva. "I had to fix my mind on my technique, forget the people."
The competition had been delayed because of rain and then held up again when a mechanical fault meant the bar could not be raised.
But it ended in a thrilling conclusion that finished just before midnight local time.
Da Silva, a former world junior champion, added 11 centimetres to his previous personal best to set a national record and become only the fourth Brazilian to win a track and field gold at an Olympic Games.
The last Brazilian Olympic gold medallist in an athletics event was Maurren Maggi, who won the women's long jump at Beijing 2008.
'Disrespected like Jesse Owens'
World record holder Lavillenie had to appeal for quiet from the Rio crowd as he prepared for a jump at 6.08m that would have put him back into the lead.
He also gave a thumbs-down gesture to the cameras.
"In 1936, the crowd was against Jesse Owens," he said. "We've not see this since. We have to deal with it.
"There is no respect, no fair play. It's the Olympics. If there's no respect in the Olympics, where can we get respect? I'm very, very sad and disappointed by the Brazilian public that was in the stadium.
"Better to stay at home in front of your television than come and whistle. At least then we'd have people in the stadium who want to watch sport."
African-American athlete Owens won four gold medals at the 1936 Olympics in Berlin, which were being used by Adolf Hitler to promote Nazi ideologies of racial superiority.
Lavillenie added: "It really disturbed me, I felt the nastiness of the public and we do a sport where you never see that.
"You see it in football. It is the first time I have seen it in track and field. It is the biggest moment of your life. I can't be happy about that. Now I have to wait four years to get back the gold."
Lavillenie later apologised for his comments, saying he made the Jesse Owens comparison immediately after the competition when very upset.
American vaulter Kendricks said: "Brazil is an emotional place, a place that has a culture around football, it's not necessarily against the other man. I took it with a grain of salt that they were booing."
Former Olympic javelin silver medallist Steve Backley:
"No way in your life have you ever seen drama such as this. The place has gone wild. How on earth has he done that? The jump of his life."
Former Olympic 1500m silver medallist Steve Cram:
"I've seen some things in my years competing and watching athletics... that has got to be one of the best moments. Home crowd, home boy, higher than ever, better than ever."
BBC Sport's Tom Fordyce
"That might just be the moment Brazil's Olympics have been waiting for. Every Games needs an iconic gold in the Olympic Stadium - think Cathy Freeman in Sydney, Michael Johnson in Atlanta, Fermin Cacho in Barcelona, the Mo/Jess/Greg triptych in London - but with so few chances and all of them outsiders, we thought it might not happen in Rio.
"A local kid put that right in spectacular fashion, destroying his old personal best, smashing the Olympic record, dethroning the reigning champion."
Subscribe to the BBC Sport newsletter to get our pick of news, features and video sent to your inbox.