Colombia topped Group H thanks to Yerry Mina's header in a 1-0 win over Senegal that sent the African side out of the World Cup by virtue of their fair play record - the first nation to exit the tournament by the method.
Both teams were on track to move into the knockout stages with 16 minutes remaining in Thursday's clash at the Samara Arena, due to Japan trailing 1-0 to Poland in Volgograd.
But Mina - also on target in Colombia's win over Poland last time out - proved the matchwinner for his side with a superb late header that was celebrated in style with a choreographed team dance.
Japan qualify in second place from Group H despite losing to already eliminated Poland. Senegal exit having received six yellow cards to Japan's four.
Senegal had a first-half penalty ruled out following a VAR review, while Colombia's key man James Rodriguez was substituted before the break and could be a doubt for the knockout rounds.
Group G's top two England and Belgium await Colombia and Japan in the last 16, with Senegal unfortunate to be knocked out by the slimmest of margins.
M'Baye Niang missed an early opportunity but the opening exchanges were cagey before referee Milorad Mazic awarded Senegal a penalty in the 17th minute.
After consulting VAR, Mazic judged defender Davinson Sanchez to have won the ball before making any contact with Sadio Mane.
Colombia were struggling to gain a foothold and they were dealt a blow after half an hour.
News of Jan Bednarek's goal for Poland gave a lift to fans of both Colombia and Senegal as the tension levels in Samara continued to rise.
Sadio Mane's slip as he took a free-kick in the 64th minute, the Liverpool forward sending the ball wildly off-target, summed up the lack of quality in the match.
Kalidou Koulibaly got a vital touch on a Luis Muriel drive to deflect the ball narrowly wide as Colombia threatened to turn the group on its head.
And in the 74th minute Colombia scored the decisive goal of the game, Juan Quintero's cross perfect for Barcelona defender Mina to rise highest and crash home a stunning header that went through goalkeeper Khadim N'Diaye.
Come for the Yerry Mina goal, stay for the 🔥 celebration! 🇨🇴 pic.twitter.com/zTgeAbBagD— FOX Soccer (@FOXSoccer) June 28, 2018
Senegal knew they were heading out and responded well to Mina's goal, Ismaila Sarr missing a fine chance after being picked out by Mane.
Colombia settled for their one-goal lead and, despite growing increasingly desperate and frantic in the closing minutes, Senegal could not force in an equaliser to keep them in the World Cup, their fair play record giving them an unwanted piece of history.