Lucas Moura's dramatic late goal sent Tottenham through to the Champions League knockout stages by earning a 1-1 draw at Barcelona.
Spurs, who had to match Inter Milan's result against PSV Eindhoven, were heading out of the competition and into the Europa League for the second time in three seasons as they trailed to Ousmane Demebele's early goal for most of the game and the Italians came from behind to level.
But, having missed chance after chance at the Nou Camp, Moura finally came to Spurs' rescue as he converted Harry Kane's cross with five minutes remaining.
It was the least they deserved as only an inspired performance from Barca number two Jasper Cillessen protected his side's five-year unbeaten run at home in European football, although ultimately they will be grateful to PSV for their favour in Italy.
A long night looked on the cards when the hosts, who were already through as Group B winners and opted to leave Lionel Messi on the bench, went ahead early on.
When Kyle Walker-Peters went to bed on Monday night he would have been dreaming of a magical night in the Nou Camp, but instead he ended up enduring a nightmare start as he was at fault for Demebele's seventh-minute opener.
The young right-back, playing his first Champions League game because first-choice pair Kieran Trippier and Serge Aurier were injured, was easily robbed of possession by Dembele on the halfway line, then completely outpaced, allowing the France international to race in on goal and slide a finish under Hugo Lloris.
It was a start Spurs would have been dreading, but, perhaps buoyed by news of PSV's early goal in Milan, they began to settle into the game and had chances to level.
First Christian Eriksen played in Danny Rose down the left, but the full-back's low cross just evaded a sliding Son Heung-min, who was then presented with an even better chance.
He was set free by Dele Alli, fought off Thomas Vermaelen's challenge and went through on goal, but saw Cillessen save his shot with his feet.
In the end Spurs were lucky to go into half-time with their deficit at one as Philippe Coutinho danced his way into the penalty area, but his shot grazed a post and went wide.
Not wanting to rely on PSV, Spurs started the second period really well and Cillessen pulled off a super stretching save to keep out Eriksen's effort before Harry Kane burst clear but uncharacteristically sent his effort wildly off target.
Another chance went begging as Rose's cutback was poor, with Kane stood waiting, while Son shot tamely at Cillessen from the edge of the area when he should have done better.
Even the introduction of Messi could not stem the tide of Spurs attacks, but they could just not find the net and another chance went begging when man-of-the-match Cillessen blocked another Eriksen effort at the far post.
Things changed when Inter equalised, meaning Spurs now had to score, and they had further chances as Cillessen again pulled off a fine save to deny Moura.
Eventually Barca, who hit a post again through Coutinho, saw their luck run out as Spurs grabbed their lifeline five minutes from time.
Kane broke free down the left and centred for Moura, who rammed home from eight yards.
Rose wasted a chance for Spurs to look after their own business and avoid a nervous finish, but he blazed over after Kane's clever reverse pass.
But the miss did not prove costly as PSV held on at the San Siro, allowing Tottenham to celebrate a place in the last 16.