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. Stanković 68'
for T. Jun 83'
|Neymar rejects agent´s anti-Scolari Twitter tirade|
|Allegri undecided on Italy job|
|Fernando idolises City team-mate Toure|
|Arteta: FA Cup will inspire Arsenal´s Premier League tilt|
|Evergrande confirm Gilardino signing|
|Howedes calls for team effort to stop Messi|
|Kuyt: Van Gaal can succeed at United|
|Argentina fined for player no-show|
|Neymar: ´I could be in a wheelchair´|
|Mascherano: I tackled doubts to block Robben|
|Zaccheroni: I leave Japan in a good spot|
|Aguero: Argentina ready to give everything|
|UEFA Europa League Review: Gothenburg leave it late, Sillamae stun Honka|
|Klose lauds Ronaldo after scooping record|
|Iran refute Susic claims|
|Fernandez named Deportivo boss|
|Argentina have no chance, says Robben|
|Hierro to replace Zidane as Real first-team coach|
|Rhodes signs new Rovers deal|
|Arsenal complete Sanchez swoop|
|Inzaghi backs under-fire Balotelli|
|Defeat has overshadowed display - Vlaar|
|Maradona: Germany full of themselves|
|Barry hoping for England recall|
|Green extends QPR stay|
|Shanghai Shenhua 1 Guangzhou Evergrande 2: Rong leaves it late in dramatic win|
|Germany hope for Brazilian support|
|Torino striker Cerci in demand|
|FIFA critcised following Mascherano incident|
|Bernat happy at Bayern despite bad memories|
|Giggs backs Van Gaal to thrive at Old Trafford|
|Tadic can fill Lallana void - Koeman|
|New five-year deal for Nasri|
|Barcelona release injury-hit Cuenca|
|Suarez appeal rejected|
|La Decima a reflection of Di Stefano - Perez|
|Buoyant Mazzarri eager for Inter success|
|Mandzukic joins Atletico|
|Van Gaal criticises third-place play-off|
|Halilhodzic yet to decide future|
|Mandzukic eager for Simeone link-up|
|Davies hoping for Hull deal|
|Poyet hopeful over Altidore fitness|
|Diego close to ´dream´ Fenerbahce move|
|Inter loan out youngsters|
|Fired-up Cole can inspire Villa, claims Lambert|
|Hughes hailed for winning over Brit doubters|
|Hajrovic signs for Bremen|
|Hull can buck Europa League trend, says Meyler|
|Mertesacker talks up German chances|
|Swansea reveal Tottenham contact over Davies, Sigurdsson|
|Lloris pens five-year deal at Tottenham|
|Fernandinho: ´The pain is big´|
|MLS Preview: Portland aim for swift revenge against Seattle|
|Sabella: Germany have an advantage|
|Second Argentine journalist dies in Brazil|
|Aguero: Argentina defied critics|
|Impressive Mascherano thrilled with final´s berth|
|Zuniga offered protection by Colombia|
|Germany vowed not to ´humiliate´ Brazil|
|Hong resigns from South Korea post|
|Third-choice Vlaar ´wasn´t nervous´|
|Van Gaal: I wanted Krul in the shootout|
|Argentina: Key factors in reaching the final|
|Sabella revels in semi-final win|
|Proud Robben feels pain of World Cup exit|
|FIFA World Cup: Netherlands 0 Argentina 0 (after extra time, 2-4 on penalties)|
|Susic signs two-year extension with Bosnia-Herzegovina|
|Hummels in race to make World Cup final|
|Scolari still baffled by Brazil collapse|
|Spendlhofer and Benedetti leave Inter|
|Neymar ´recovering well´ from injury|
|Villarreal sign Jonathan dos Santos|
|Arteta happy at Arsenal, insists agent|
|Birsa makes Chievo loan switch|
|FIFA suspends Nigeria over political interference|
|Di Stefano funeral held in Madrid|
|Hangeland scathing of ´difficult´ Magath|
|Thiago Silva in fan plea|
|Isgrove earns fresh one-year deal at Southampton|
|Morata edges closer to Juve switch|
|Nugent pens two-year extension at Leicester|
|Gomez delight with ´perfect´ Germany|
|Costa Rica to discuss Pinto future|
|Arfield agrees Burnley extension|
|Allardyce targets four more signings|
|K.League Review: Jeonnam close gap on Pohang, Jeonbuk|
|Maradona: Thrashing damages Brazil´s image|
|Kasami makes Olympiacos move|
|Chelsea complete Pasalic signing|
|Helenius makes temporary Aalborg return|
|Higuain set for Napoli stay|
|Basta targets return to Europe with Lazio|
|Lewandowski willing to adapt for Bayern|
|New Hull deal for Jakupovic|
|Atletico agree Mandzukic deal, claims Sammer|
|Fulham seal Stafylidis loan|
|Alves pens new Valencia deal|
|Ochoa to take time over future|
|Brown could miss three months|
|Adams: Norwich will not overspend|
|Gundogan unsure when rehab can step up|
|Stoke chairman wants long Begovic stay|
|Brazilian media reacts to semi-final exit|
|Icardi vows to remain at Inter|
|Robben is player of the World Cup, says Kluivert|
|Klose focused on final after breaking record|
|Prandelli takes aim at Balotelli, Rossi|
|Schweinsteiger sorry for Brazil battering|
|Brazil scarred for life, says Fred|
|Sabella: Argentina ´have already won´|
|Muller stunned by rout|
|Low lauds ice-cool Germany|
|Tearful Luiz apologizes for semi-final loss|
|Scolari sorry for ´catastrophic´ Brazil hammering|
|Brazil join sport´s biggest chokers|
|Reality kills Brazilian dream on a surreal night|
|FIFA World Cup: Brazil 1 Germany 7|