Striker Kensuke Nagai fired Japan to the brink of the Olympic quarter-finals with a late winner against Morocco.
The Grampus Eight frontman struck with an instinctive lob six minutes from time to settle a tight Group D encounter.
Bustling Kayserispor striker Noureddine Amrabat should really have opened the scoring for Morocco with 18 minutes gone, but saw his close-range shot blocked by a combination of keeper Shuichi Gonda and full-back Gotoku Sakai.
Gonda had to pull off a good save to keep out Zakaria Labyad's swerving 25-yard drive 11 minutes before the break, but the Japanese belatedly responded when Yuki Otsu, the hero of the 1-0 victory over Spain, sent a deflected attempt inches wide.
The woodwork denied Hiroshi Kiyotake with 62 minutes gone when his 20-yard piledriver came back off the bar and hit Amsif before the keeper managed to cling on to the loose ball.
Amsif palmed away Otsu's effort eight minutes later, but was finally beaten six minutes from time when Nagai ran on to a ball over the top and calmly lifted it over him as he advanced to snatch victory.
However, it took a fine double save by Gonda to ensure the points remained with his side as Labyad and then substitute Omar El Kaddouri went agonisingly close at the death.