Brazil survived a World Cup scare in the round of 32 when it fought back to beat Japan 2-1 after Gabriel Martinelli squeezed in a shot at the far post deep in stoppage time on Monday.

Brazil, which will next face Norway ​or Cote d’Ivoire in New Jersey on Sunday, improved after the break with Japan taking an ‌early lead ‌and shackling the attack of the five-time champion for much of the opening ​period.

Martinelli’s winner in the 95th minute came at the end of a tense match and was the latest winning goal in normal time of a World Cup knockout game since 1966. Brazil players and staff ⁠hugged each other on the pitch after the match as the Japanese players watched on in disbelief.

“I can’t explain how ⁠I feel,” Martinelli said. “It’ll only really sink in (in) a while. Thank God I managed to score the goal today. I’m so happy for the team, who gave it their all. ​I’m lost for words.”

Japan’s Kaishu Sano stunned ⁠Brazil in the 29th minute when he intercepted Danilo’s misplaced pass before driving toward goal and rifling a shot past goalkeeper Alisson Becker to send the ⁠outnumbered Samurai Blue fans ​into delirium.

Japan put on a first-half defensive masterclass as it sucked up ​pressure with defenders flying around the pitch, breaking up passes and closing down space any ​time a ‌Brazilian player had the ball.

Brazil coach Carlo Ancelotti must have said something at halftime as his players came out with a sense of urgency and created a number of chances, pushing forward at a faster pace and loading the box.

“We didn’t lose our patience, we had a lot ‌of resources on the pitch and on the bench,” Ancelotti said. “Japan isn’t an easy opponent. It’s very organized and intense.

“I was saving Neymar for extra time. He was going to enter the pitch on minute 105 if we hadn’t scored the second goal. I didn’t want to change the structure because the team was playing well.”

Brazil, however, ​did ​not need its all-time leading scorer and equalized when Casemiro, who had missed ​a golden chance moments earlier, outjumped his marker to nod in a far-post header in the 56th minute ⁠from a Gabriel Magalhaes cross.

Vinicius Junior looked like he had found the winner when his mazy run ended with Japan goalkeeper Zion Suzuki brilliantly pushing a shot onto the post much to the disbelief of the sea of yellow-clad supporters in the packed stadium.

Japan players regrouped and kept ​Brazil at bay until Bruno Guimaraes received the ball on the edge of the box before hesitating and then slipping it through to Martinelli who made no mistake with a clinical finish.

The result denied Japan a first-ever World Cup knockout win, and Brazil stayed on course to reach the quarterfinals, as it has in every tournament since a last-16 exit in 1990.