Zenit St Petersburg lost 4-1 at Austria Vienna but reached the UEFA Champions League knockout phase due to Porto's loss at Atletico Madrid.
The Russian side required victory to progress from Group G without relying on the outcome in the Spanish capital and Aleksandr Kerzhakov put them on course to do just that with the opener in the 35th minute.
However, Vienna scored three goals – two courtesy of Philipp Hosiner – within seven minutes either side of the break to leave Zenit facing an anxious wait before Roman Kienast added a fourth late on.
Porto were unable to recover a first-half deficit, resigning them to UEFA Europa League football and sending Zenit through to the Champions League round of 16 with only six points from six games.
Vienna, who were guaranteed to finish bottom before kick-off, celebrated their first win in Europe's elite competition, with Tomas Jun also on target.
The home side were without defender Lukas Rotpuller and midfielder Bernhard Luxbacher due to injury, while playmaker Danny missed out for Zenit.
That did not prevent the Russian heavyweights creating chances in an opening half hour they dominated.
Within 180 seconds, Hulk fired over the crossbar following a neat passing move. Domenico Criscito was then close to connecting with a Viktor Fayzulin cross, before Hulk created space for himself with some delightful footwork only to see his shot from the edge of the box blocked by Kaja Rogulj.
Zenit eventually broke the deadlock in the 35th minute. Kerzhakov's clever movement coupled with defender Manuel Ortlechner's untimely slip allowed the former to race on to Hulk's reverse throughball. Kerzhakov took it round goalkeeper Heinz Lindner and slotted home into the empty net.
Out of nothing, however, Vienna equalised on the stroke of half-time. Hosiner robbed Zenit of possession, played a superb one-two with Marko Stankovic and slotted the ball across goalkeeper Yuri Lodygin and into the bottom corner.
Within six minutes of the restart, Vienna were 3-1 up. First, following a very poor goal-kick from Lodygin, Markus Suttner controlled the ball sublimely and crossed to give Jun a tap-in.
Then Florian Mader's long-range strike was parried by Lodygin straight into the path of Hosiner, who thumped the ball home to complete his brace.
Zenit tried to respond as Konstantin Zyryanov went close from distance, Hulk forced Lindner into a smart save and Axel Witsel saw his powerful strike go narrowly over the crossbar.
But Vienna completed a 4-1 success in injury time, when the brilliant Hosiner crossed for substitute Kienast to fire home.
|16||P. Hosiner||44' 51'|
|Coach: N. Bjelica|
for T. Murg 60'
for M. Stankovic 68'
for T. Jun 83'
|Ancelotti: Growing transfer fees nothing special|
|Eriksson: Ibrahimovic and Mourinho combo enough to win Premier League|
|Meunier: I could not reject PSG|
|Klopp: I didn´t want Mkhitaryan|
|Anything could happen before transfer window shuts - Zidane|
|Montoya leaves Barca base, nears Valencia switch|
|Wijnaldum: I´m happy to play anywhere|
|Klopp backs Mignolet after Karius injury|
|Liverpool suffer Karius injury blow|
|Ranieri confident Mahrez will stay as contract talks continue|
|Emery confirms interest in Jese|
|Higuain´s Juventus move not about money - agent|
|Wolves sack head coach Jackett|
|Zidane: Ronaldo unlikely to play Madrid La Liga opener|
|Ibrahimovic: United fans are waiting for me|
|Deulofeu shines for Everton, Cook opens Bournemouth account|
|Higuain out to emulate Del Piero|
|Kante does his talking on the pitch - Conte|
|Mourinho explains Fosu-Mensah snub|
|Klopp: No more unwanted players at Liverpool|
|Inter want more than €60m for Icardi - Thohir|
|Leicester can replace Kante - Ranieri|
|Lazio complete Wallace signing|
|Gueye set to join Everton, confirms Di Matteo|
|Tuchel: Transfer market has gone cash crazy|
|Leicester hand King new four-year deal|
|No deal done for Pogba, says Raiola|
|Rooney: Mourinho impact already huge|
|Lafferty hit with FA betting charge|
|Top-four finish never enough for Arsenal, insists Wenger|
|Partey hoping to make his mark on Atletico squad|
|Ibrahimovic in, Schweinsteiger out as United head for Galatasaray friendly|
|Vietto set for Sevilla after completing medical|
|I rejected Besiktas to fight for Barcelona spot, reveals Mathieu|
|De Laurentiis fumes at Higuain´s ´lack of respect´|
|Promising Janssen boosts Tottenham´s title hopes|
|Besiktas sign Adriano on three-year contract|
|Tottenham 0 Atletico Madrid 1: Godin grabs the winner|
|Gomis completes Marseille loan move|
|Iniesta surprised at Casillas-Del Bosque spat|
|New Juve signings do not guarantee success - Allegri|
|New Juve signings do not guarantee success - Allegri|
|Middlesbrough snap up goalkeeper Guzan|
|Guardiola still loves Ribery despite jibes|
|West Ham worry over Tore injury|
|Serie A could be another one-horse race, says Eriksson|
|Schweinsteiger retires from Germany duty|
|Iniesta welcomes Barca´s midfield competition|
|Drogba: No luck in Arsenal scoring record|
|Wenger seeks ´experienced´ striker to bolster Arsenal attack|
|Eriksson and Shanghai SIPG still fighting|
|MLS All-Stars 1 Arsenal 2: Premier League giants win late as Xhaka makes debut|
|Conte: I want aggression and intensity|
|Wimmer backs physical Janssen for Tottenham success|
|Klopp: I wouldn´t spend £100m on one player|
|Sampaoli: Taking Argentina job would be irresponsible|
|Payet absence no excuse - Noble|
|Gabriel Jesus expects Palmeiras exit amid Manchester City rumours|
|Domzale 2 West Ham 1: Crnic double stuns Bilic´s side|
|Juventus target Gabriel Barbosa says Santos exit is close|
|Leicester duo ready for ´once in a lifetime´ Champions League journey|
|Fabregas apologises for Klavan lunge|
|Reschke: Guardiola wanted Tuchel to be his successor|
|Pochettino expecting further Tottenham signings|
|Given retires from international football|
|Abdi and Pudil swap Watford for Wednesday|
|Leicester sign Chilwell to new five-year deal|
|Klopp pre-season ´most intense ever´ for Sturridge|
|Simeone backs Griezmann for Ballon d´Or final three|
|Puskas Award winner quits football - to become a gamer|
|Simeone: Champions League final felt like a death|
|Higuain: I have to prove my worth to Juventus|
|Guardiola confirms interest in Sane and Stones|
|Moreno set for Manchester City switch and Deportivo loan, claims agent|
|De Laurentiis pushed me into Juventus move - Higuain|
|Savic seeking to put injury woe behind him|
|Borussia Dortmund 1 Manchester City 1 (5-6 pens): Gunn´s shootout saves earn Guardiola first win|
|Oblak: Atleti need consistency and luck|
|Warburton rubbishes Van Persie rumours|
|Hospitalised Grujic ´can´t remember anything´, says Klopp|
|Premier League, Serie A appeal to Simeone|
|Copa Libertadores success ´a dream´ for Borja|
|Pochettino honoured by Simeone comparisons|
|Argentina have not asked for Sampaoli - Monchi|
|Ancelotti: Fitness the key for Bayern|
|Bayern win ´a small foundation´ for Montella´s Milan|
|Icardi missing due to injury - Mancini|
|Emery satisfied with warm-up win over Madrid|
|Conte quiet on Tevez, apologises for Fabregas red|
|´It was far from a friendly´ - Klopp on Chelsea defeat|
|Madrid off the pace, concedes Zidane|
|Chelsea 1 Liverpool 0: Cahill´s header seals win|
|Grujic says Chelsea´s Matic told him to sign for Liverpool|
|Bolasie wants to see Berahino and Benteke at Crystal Palace|
|Rodgers hails ´outstanding result´ as Celtic draw|
|Walcott claims level of MLS is close to Premier League|
|Bayern Munich 3 AC Milan 3 (3-5 on penalties): Bonaventura seals win|
|Atletico Nacional 1 Independiente del Valle 0 (2-1 agg): Borja secures Copa Libertadores crown|
|Icardi absent again as Inter held by Estudiantes|
|Real Madrid 1 Paris Saint-Germain 3: Zidane oversees poor pre-season start|
|Hazard vows to rediscover best Chelsea form|
|Klopp reveals why he sent Sakho back to Liverpool|
|Tevez: Conte wanted me at Chelsea|
|Sunderland hopeful Defoe will be fit for Man City opener|
|Sundowns overcome Zamalek to book semi-final spot|