Philippe Coutinho and Neymar broke down dogged Costa Rica in injury time on Friday, sealing a 2-0 win for Brazil that propels the five-time champions towards the World Cup last 16.
The Central Americans looked likely to hold on for a hard-earned draw, particularly after Neymar had a penalty award chalked off by referee Bjorn Kuipers after he consulted the Video Assistant Referee.
But Coutinho and Neymar finally broke through, scoring in the 91st and 97th minutes to put Tite’s side on the brink of the knockout stages.
At the final whistle, Neymar sat down on the grass and wept, with the emotion of victory hitting home after the tense Group E contest at the Saint Petersburg Stadium.
Neymar started despite limping out of training on Tuesday with a hurt ankle, which the Brazilian FA said was sustained as a result of snapping Swiss defenders.
After a ponderous start, Brazil enjoyed a gradual crescendo during the first period but their dominance in possession was not reflected in chances created.
Neymar faced the most devoted of markers in Costa Rica’s Cristian Gamboa, the Brazilian spending most of the half hopping over scything tackles or dodging past a barging shoulder.
It was a compelling battle. One sumputous Neymar flick sent the ball flying over Gamboa’s head and later he made an excellent run onto Coutinho’s pass, only to squander the chance with a heavy touch.
Marcelo, Coutinho and Neymar, however, hardly make for the most conscientious combination out wide and when Johan Venegas ran clear down the right, his pullback should have been converted by Celso Borges, who skewed past the post.
Brazil might have had a penalty when Oscar Duarte blocked Paulinho at a corner and Costa Rica rode their luck again after the break, as Neymar, Gabriel Jesus and Coutinho all went close.
Jesus’s header crashed against the crossbar and after some excellent work by Paulinho, Coutinho’s follow-up hit the ever-present Gamboa on the line.
Neymar fired over from Paulinho’s cutback and Coutinho shot straight at Keylor Navas after, again, Paulinho had teed it up.
With 20 minutes left, Gamboa made his first mistake and Neymar should have capitalised. A sloppy touch allowed the striker to cut inside from the left but his bending finish curved around the outside of the post.
There was more drama to come. With just over 10 minutes left, Neymar’s turn prompted Giancarlo Gonzalez to lose his footing and put his arm across the Brazilian’s chest.
Neymar arched back as if losing his balance before falling to the ground. Kuipers pointed to the spot but after reviewing the video replay, reversed his decision.
Frustration brewed but Costa Rica’s resistance was finally ended in the 91st minute.
Marcelo’s deep cross was kept alive by Roberto Firmino and a loose touch by Jesus dribbled perfectly into Coutinho’s path. Six yards out, he sidefooted home.
Costa Rica conceded again right at the death. Substitute Douglas Costa squared for Neymar to finally find the net.