Brazil was battered by Switzerland and held to a draw in its World Cup opener. And until the very end in its second act, it was stifled once again.
But goals from Philippe Coutinho in Neymar in stoppage time secured a vital 2-0 victory in Saint Petersburg, sending Brazil to four points in Group E, while Costa Rica has been eliminated with a match to spare.
Keylor Navas was tremendous in goal again, while Neymar had a late penalty call overturned by VAR, and while it looked like Brazil was going to have to settle for the draw, its attacking stars came through with the clutch, late goals.
Brazil came out on the front foot, and Coutinho fired the first warning shot in the fourth minute. On the opposite side of the field from where he opened the scoring vs. Switzerland, the Barcelona star launched a long-range attempt, though this one flew over the bar.
Costa Rica nearly connected for a stunner eight minutes later. On a lightning quick counterattack, a sharp cutback pass played Celso Borges into the top of the box, where he connected for a first-time effort that rolled just wide of the far post.
Brazil dominated the possession, and Neymar saw plenty of the ball. While he suffered from more physical treatement in the opening half, he also had the time and space to pull off tricks like this.
Brazil had a goal disallowed in the 26th minute. Neymar had a ball tackled away, but it landed right at the foot of Marcelo. The Real Madrid left back slipped in a pass for Gabriel Jesus, who finished, but the Man City forward was well offside at the time of the pass, and the assistant referee's flag went up to nullify the score.
Costa Rica continued to stifle Brazil's creativity in the final third, but that didn't stop the Seleção from firing from long range, which is what Marcelo tried in the 41st minute, only to have Keylor Navas make a diving save by his right post to keep it 0-0.
Navas came up big again at the start of the second half off a hectic sequence. A ball played back to Navas inside the box was quickly cleared, but not completely from danger. A second ball was sent in that Navas wound up securing as Neymar lurked at the goal mouth.
Moments later, Gabriel Jesus rang the crossbar with a header, and Coutinho's follow-up was directed wide by Cristian Gamboa, with Brazil continuing to apply pressure as it went after the opening goal.
The pressure continued in the 57th minute, when Neymar had a golden opportunity in the center of the box, redirecting a cross on frame, only for Navas to tip it just over the bar.
A minute later, Navas again came up with the save, with Coutinho taking a layoff pass and firing low from 15 yards, only for the goalkeeper to make the clean stop.
Neymar forced another save from Navas in the 64th minute, taking a speculative, low shot from 20 yards that Navas spilled, but he had the time to recover and claim the rebound without much trouble.
Brazil had another chance in the 70th minute off a corner kick, with Casemiro having a clear header from the center of the box. He bounced it right at Navas, though, who made the sure-handed save on the goal line.
The next best chance came in the 72nd minute. As Brazil pushed forward, a wayward touch in the back gifted Neymar the ball and an avenue in on goal. He elected to fire away from the top of the box, curling his right-footed chance inches wide for the upper right-hand corner of the goal, wasting a clear look.
A controversial moment came in the 80th minute. Gabriel Jesus had played the ball to Neymar in the box, and as he cut back to create space to shoot it appeared that Giancarlo Gonzalez impeded him by putting an arm across his torso. Neymar made a show of the foul, and while an initial penalty was given, VAR alerted referee Bjorn Kuipers, who checked the replay and overturned his initial call.
Brazil finally got its breakthrough as stoppage time hit. Marcelo sent in a cross from the left that was headed back across goal by substitute Roberto Firmino. Gabriel Jesus was able to toe poke it with his back to goal, putting the ball in the path of a streaking Coutinho, who fired home from close range to finally beat Navas.
Neymar iced it a few minutes later, latching onto a cross from Douglas Costa after Casemiro had pushed forward, and finishing in front of goal to secure the 2-0 win and the three points.
Here were the lineups for both teams:
Here are the rosters for both sides:
Goalkeepers: Alisson (Roma), Ederson (Man City), Cassio (Corinthians)
Defenders: Danilo (Man City), Fagner (Corinthians), Thiago Silva (PSG), Miranda (Inter), Marquinhos (PSG), Pedro Geromel (Gremio), Marcelo (Real Madrid), Filipe Luis (Atletico Madrid)
Midfielders: Casemiro (Real Madrid), Paulinho (Barcelona), Fernandinho (Man City), Renato Augusto (Beijing Guoan), Philippe Coutinho (Barcelona), Fred (Shakhtar), Willian (Chelsea)
Forwards: Neymar (PSG), Roberto Firmino (Liverpool), Gabriel Jesus (Man City), Douglas Costa (Juventus), Taison (Shakhtar)
Goalkeepers: Leonel Moreira (Herediano), Keylor Navas (Real Madrid), Patrick Pemberton (LDA)
Defenders: Johnny Acosta (Aguilas Dorados), Francisco Calvo (Minnesota United), Oscar Duarte (Espanyol), Cristian Gamboa (Celtic), Giancarlo Gonzalez (Bologna), Ronald Matarrita (NYCFC), Bryan Oviedo (Sunderland), Ian Smith (Norrkoping), Kendall Waston (Vancouver Whitecaps)
Midfielders: Randall Azofeifa (Herediano), Christian Bolanos (Saprissa), Celso Borges (Deportivo La Coruna), Daniel Colindres (Saprissa), David Guzman (Portland Timbers), Bryan Ruiz (Sporting Lisbon), Yeltsin Tejeda (Lausanne), Rodney Wallace (NYCFC)
Forwards: Joel Campbell (Real Betis), Marco Urena (LAFC), Johan Venegas (Saprissa)
Manager: Oscar Ramirez