Substitute Nacer Chadli scored in the dying seconds as they came from two goals down to set up a mouthwatering clash with five-time champions Brazil on Friday in Kazan.
The distraught Japanese, who went 2-0 up with goals by Genki Haraguchi and Takashi Inui early in the second half, fell to the turf after Chadli poked the ball home.
He made good use of Thomas Meunier’s cross four minutes into added time, after the lone Japanese defender had gone after Romelo Lukaku.
Much-fancied Belgium, who had taken a conservative approach to the game, got back into contention with late goals by Jan Vertonghen and Marouane Fellaini before Chadli struck.
It was a demonstration of coach Robert Martinez’s tactical nous, quickly switching from 3-4-3 to 3-5-2 and bringing in two resourceful substitutes who went on to get their last two goals.
“That’s what happens in the World Cup. It was a test of character and a test of the team. It tells you everything about this group of players,” said Spaniard Martinez.
Japan coach Akira Nishino, whose side agonisingly failed to reach the last eight for the first time, added: “We were leading. We were going to win, but I didn’t expect this kind of reversal of the result.
“I thought this is a World Cup, and we were faced with the strength in depth of Belgium. That’s how I felt at the end of game.”
One of the most exciting teams of the group phase, Belgium faced an embarrassing exit but finally clicked.
It helped them to become the first team to win a World Cup knockout game from two goals down since West Germany beat England 3-2 after extra time in 1970.
Belgium’s “golden generation’’ have now scored 12 goals in four games in Russia ahead of a last eight clash on Friday with Brazil, who beat Mexico 2-0 earlier on Monday.
With centre back Vincent Kompany back in the lineup for the first time since picking up a groin strain in a warm-up game, Belgium had looked safe at the back.
But they were uninspired upfront during a first period when they were on top but toothless.
Both teams fought a tight midfield battle but their forwards froze in the area and Belgium’s wide players, Meunier and Yannick Carrasco, did not take risks going forward.
This effectively turned a 3-4-3 formation into a more conservative 5-2-3 system.
Japan got closest to a goal in a dull first half when Belgium goalkeeper Thibaut Courtois let the ball slip from his hands and between his legs.
But the Chelsea FC goalkeeper recovered before it crossed the line.
The Japanese were ahead soon after the break, though, when Haraguchi beat the offside trap and ran into the area to beat Courtois with a cross-shot in the 48th minute.
The Red Devils responded but Hazard’s shot rattled the post.
However, it was Japan who doubled their tally in the 52nd when Inui picked up the ball 25 metres out and fired a missile into the back of the net.
Belgium were still struggling but they pulled a goal back after 69 minutes when Vertonghen looped a header from a high clearance back across goal into the far top corner.
The momentum had by now shifted and, in the 74th, Eden Hazard’s cross was met by Fellaini.
He equalised from close range with a powerful header within 10 minutes of coming on.
Belgium continued to push forward and both Chadli and Lukaku forced Japan goalkeeper Eiji Kawashima into spectacular saves with powerful headers four minutes from the end.
Just when all thoughts were being prepared for another 30 minutes of play, Keisuke Honda’s 30-metre free-kick was parried away by Courtois in stoppage time.
The goalkeeper launched the ball to Kevin De Bruyne to make a beeline upfield before finding Meunier, whose cross was met by Chadli for the winner.