Substitute Nacer Chadli was Belgium's hero on a humid night in Rostov-on-Don, scoring in the fourth minute of injury time to seal the dramatic victory.
Japan had stunned Roberto Martinez's third-ranked side by racing into a two-goal lead in the second half through Genki Haraguchi and Takashi Inui.
With Belgium looking to be heading home, Jan Vertonghen -- the defender whose error had led to Japan's opener -- made amends with a goal to put Belgium back in the game before Marouane Fellaini's powerful header brought them to 2-2.
It was goalkeeper Thibaut Courtois who started the slick move that decided the match, rolling the ball out to Kevin De Bruyne, who raced upfield before feeding Thomas Meunier.
The defender's cross was intelligently dummied by Romelu Lukaku, allowing West Bromwich Albion's Chadli to slot past Japan 'keeper Eiji Kawashima.
The Japan players slumped to the turf and coach Akira Nishino said they were too stunned to talk about the match immediately afterwards.
Belgium coach Martinez expressed his pride in the players.
"In the World Cup you want to be perfect but it's about getting through, it's about winning," Martinez said.
"It was a test of character and you see the reaction of our subs coming on to win the game. It tells you everything about this group of players."
Brazil on the march
Brazil stayed on course for a sixth title as Neymar scored and created a goal for substitute Roberto Firmino to snuff out Mexico's challenge.
Neymar was criticised for his early performances in Russia as he eased his way back to fitness after a broken foot bone, but he carved open a tough Mexican defence without quite reaching his dazzling best.
After a goalless first half in the heat of Samara, the world's most expensive player tapped in from the impressive Willian's cross for his second goal of the tournament on 51 minutes.
As Brazil pressed their advantage, Neymar set up Firmino for another close-range finish that sealed the 2-0 victory.
In between, he writhed in agony on the turf after a Mexican opponent appeared to stand on his ankle, but the referee ruled there had been no foul and Neymar was soon on his feet and sprinting.
Neymar hit back at his critics afterwards.
"I don't care much for criticism, or praise, because this can influence your attitude," he said.
"In the last two matches I didn't talk to the press because I don't want to, I just have to play, help my teammates, help my team."
"I'm here to win. I can always improve. Today I feel much better and I'm very happy for this win."
Mexico threatened at times but their World Cup challenge ended at the first knockout stage for the seventh consecutive tournament.
Russian fans celebrated long into the night after they stunned 2010 winners Spain on penalties in an electric atmosphere at Moscow's Luzhniki Stadium on Sunday.
Veteran goalkeeper Igor Akinfeev was the hero for the hosts, saving two spot-kicks.
The win sparked an outpouring of joy on the streets of the capital, with disbelieving locals cheering, waving flags, blowing horns and yelling "Russ-i-a!"
Russia, ranked a lowly 70th in the world, will play Croatia in the last eight after similar drama in Nizhny Novgorod, where Luka Modric saw his spot-kick saved late in extra time before his team held their nerve to defeat Denmark in the penalty shootout.
Spain had been considered among the favourites but their preparations were wrecked when coach Julen Lopetegui was sensationally sacked on the eve of the tournament.
"The KO in the last 16 is another dark chapter in our history," said Spanish sports daily Marca, adding that it was "incredible naivety" to think Lopetegui's abrupt sacking would not affect the team.
Spain join 2014 winners Germany, Argentina and European champions Portugal in exiting the competition, leaving just four former World Cup winners in the tournament.
Cristiano Ronaldo and Lionel Messi, who have dominated the game for the past decade, have gone home, their hopes of ever winning the World Cup probably over.