It looked like the already-eliminated Samoans were going to frustrate the hosts as the clock ticked into stoppage time, with Japan 31-19 up but on only three tries and the Pacific islanders awarded a free kick. If they had kicked it out it would have been game over but they opted for a scrum on their own line.
A free kick was subsequently awarded to the Brave Blossoms and they pushed again, winning two penalties. They went for scrums and on the second moved it wide to Kotaro Matsushima, who crossed to spark wild celebrations.
It means that the scenario for Scotland most were predicting is playing out, with the most basic synopsis now that Gregor Townsend's men must beat Russia with a bonus point in Shizuoka on Wednesday to take them to ten points, playing pool-topping Japan's 14 in next Sunday's momentous showdown between the two teams in Yokohama.
If that is the case then Scotland would need to beat Japan while denying them any bonus points, either/or for finishing withing seven points or scoring four tries in the process. The crucial threshold is 15 points, which is the maximum the Scots can reach from their final two games. If both finish on 15, Scotland would finish higher on the head-to-head, which is the primary tiebreaker.
There remains a scenario in which Scotland could beat Japan with a bonus-point in a high-scoring game but still go out because the hosts take two bonus points in defeat.
If Scotland beat Russia without a bonus point on Wednesday, they could beat Japan with a bonus and deny them any to progress.
Straying into unlikely territory, there remains a theoretic outcome in which Ireland, who are now second in Pool A on 11 points, lose without taking anything to Samoa and Scotland could pass them if they lose to Japan with two bonus points and join the hosts in the quarter-finals.
More into the realms of possibility is that Ireland beat Samoa but fail to take a bonus point, which opens the door to Scotland, Japan and Ireland all finishing on 15 points. In that scenario head-to-head would be redundant as Ireland beat Scotland, Japan beat Ireland and Scotland would have beaten Japan. Then points difference comes into play. Currently Scotland have played two and are on +10, Japan and Ireland have played three and are on +46 and +52 respectively.
In today's game, Japan were on only two tries heading into the last ten minutes in Toyota, after Kazuki Himeno and Timothy Lafaele had put them in a winning position but short of the all-important bonus. Wing Kenki Fukuoka got the third until Matsushima's dramatic late score.