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.
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.
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.
Star player James, who won the Golden Boot at the last World Cup, was substituted with what appeared to be a recurrence of the injury that kept him out of Colombia's 2-1 loss to Japan.
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.
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.
Barcelona (@FCBarcelona) June 28, 2018
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.
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.