The five-time winners seemed poised for another draw, especially after a penalty awarded to Neymar was overturned by referee Bjorn Kuipers after consulting VAR.
However, Coutinho's 91st-minute strike rescued the Selacao an important victory which puts them top of the group, and Neymar soon struck to consign Costa Rica to elimination.
Costa Rica had the best chance of the first half on 13 minutes when Celtic defender Cristian Gamboa darted past Paulinho and pulled a cross back for Celso Borges, who stroked a side-footed shot narrowly wide.
The Selecao began to move through the gears after the opening 25 minutes and had a goal disallowed when an expert touch-and-finish on the volley from Gabriel Jesus was in vain because of the offside flag.
Passed fit despite missing training this week, Neymar had a decent opening moments later when his run off the left was spotted by Coutinho, but his hesitation allowed Keylor Navas to smother Brazil's talisman.
It looked for a long time as though Navas would keep Brazil at bay as he kept out Real Madrid teammate Marcelo and Coutinho before the break, and there were better saves to come in the second period.
Only a fingertip over the crossbar denied Neymar when he met Douglas Costa's cutback sweetly on the volley on 55 minutes, and the goalkeeper stood tall again when Coutinho ran onto a layoff from Jesus.
When Navas was beaten, Brazil were thwarted by other means as Jesus thumped a header against the crossbar, with an apparently simple Coutinho follow-up deflected around the post by a Johnny Acosta block.
Brazil's exasperation was embodied by Neymar, who squandered a glorious chance on 76 minutes when he whipped a shot over the crossbar after pouncing on a mistake from Giancarlo Gonzalez to run clear, and then saw a penalty award overturned following consulation with VAR.
Gonzalez did have a little tug on Neymar's shirt and Dutch referee Kuipers initially pointed to the spot, only to reverse his decision after looking at the video replay, adjudging the Paris Saint-Germain forward to have gone to ground too easily.
Costa Rica showed great spirit to keep Brazil to parity for 90 minutes, but their luck ran out in added time as Coutinho burst onto a knockdown from Roberto Firmino to poke the ball through the legs of Navas from close range - his second goal in as many matches.
Neymar was redeemed with virtually the last kick of the game as he cushioned a volley into an empty net after a selfless cross from Costa, securing a victory which puts Brazil in a strong position to make the last 16.
KINDLY DROP A COMMENT BELOW