Facing early elimination in the Copa América at home, Brazil finally found a way to get past Paraguay in a penalty shootout.
After two consecutive eliminations against its southern neighbour, Brazil came out on top on penalties on Thursday to avoid an embarrassing elimination in the quarterfinals of the South American tournament.
Goalkeeper Alisson made a save and Gabriel Jesus scored the decisive penalty as Brazil defeated Paraguay 4-3 in the shootout to return to the semifinals for the first time since 2007.
Alisson dived to his left to stop the initial penalty by defender Gustavo Gómez, and Gabriel Jesus sealed the victory to keep Brazil on track for its first Copa América title since 2007.
Brazil will next face either Venezuela or Argentina, which play on Friday in Rio de Janeiro.
Brazil had lost to Paraguay the last two times the teams met in the Copa América quarterfinals, in 2011 and 2015, both times in penalty shootouts.
Derlis González also missed from the spot for Paraguay, while Roberto Firmino failed to score for Brazil. Both players sent their shots wide.
González, who also missed a penalty in Paraguay's 1-1 draw against Argentina in the group stage, had scored the decisive goal in the 2015 shootout. He was one of the five players back from that team that eliminated Brazil.
Willian, Marquinhos and Philippe Coutinho converted their penalties for Brazil, while Miguel Almirón, Bruno Valdez and Rodrigo Rojas netted for Paraguay.
"My teammates did their part, they took on the responsibility and succeeded. That was crucial," Alisson said. "This was an important step toward our goal of winning the South American title."
Gabriel Jesus had missed a late penalty in Brazil's 5-0 rout of Peru in its last group game, but calmly found the net with his shot from the spot as Paraguay goalkeeper Roberto "Gatito" Fernández went the other way, igniting the Brazilian crowd of more than 48,000 at the Arena Grêmio.
"I was confident, I knew that if I took the penalty the way I'm used to taking it, I would have more chances of scoring," Gabriel Jesus said. "I was upset after the other match because I didn't take the shot my own way. This time I waited for the goalkeeper to move and just sent the ball the other way."
Gatito had been key in regulation as the visitors held on to a 0-0 draw despite having a defender sent off in the 58th minute. In the Copa America quarterfinals, extra time is not played and the match proceeded straight to penalties.
Paraguay played with 10 men after Fabián Balbuena was sent off for a foul that was initially called a penalty kick but was reversed after video review determined the foul happened outside the area.
"We have to be proud of the character shown by this team," said Paraguay coach Eduardo Berizzo, an Argentine. "We could have been rewarded with a wonderful and heroic triumph in the penalty shootout, but that doesn't take anything away from my players' great performance."
Brazil controlled possession but struggled to create scoring opportunities against Paraguay's solid defensive system.
The visitors had one of the best chances of the first half when González's close-range shot was saved by Alisson.
Brazil pressed nearly full-time after Balbuena was sent off, but couldn't capitalise on its many opportunities. Gabriel Jesus, Coutinho, Everton and Firmino all missed great chances in front of the goal.
Fernández made a great reflex save on a close-range header by Alex Sandro near the end of the match, and in the 90th Fernández could only watch as a low shot by Willian struck the post.
Brazil coach Tite said the poor field conditions didn't help Brazil's attack.
"It's absurd to have to play on a field where it's difficult to exchange passes," Tite said.
Despite reaching the semifinals in 2015 and finishing runner-up in 2011, Paraguay has won only one of its last 21 matches in the Copa América, taking advantage of penalty shootouts to advance.
Paraguay reached the last eight this year with only two points, finishing as one of the two best third-place teams from the three groups.
Paraguay and Brazil failed to make it out of the group stage in the 2016 Copa América.
An eight-time South American champion, Brazil has won the tournament all four previous times it hosted the event, the last time in 1989.
Brazil's Neymar, dropped from the squad because of an ankle injury sustained just before the tournament, watched from the tribunes at the Arena Grêmio.