Kevin Grosskreutz scored in the dying stages as Borussia Dortmund beat Marseille 2-1 to clinch top spot in UEFA Champions League Group F.
Jurgen Klopp's men went into the game knowing that a win would be enough to see them qualify for the next stage, but any sort of slip-up would afford Napoli the chance to progress.
Last season's beaten finalists looked to be on their way to a routine victory when Robert Lewandowski put them ahead in the opening stages.
However, Marseille - managed by sporting director Jose Anigo following Elie Baup's dismissal last week - quickly levelled matters through defender Souleymane Diawara as they sought to avoid the ignominy of finishing the group stage with no points.
Dortmund wasted numerous chances to go back in front in a one-sided second half at the Stade Velodrome, Lewandowski and Marco Reus among those to miss gilt-edged opportunities.
But the Bundesliga club finally breached a stout Marseille defence as Grosskreutz struck three minutes from time to seal top spot as previous group leaders Arsenal were beaten 2-0 at Napoli.
Defender Rod Fanni made his return from injury for Marseille, while Benjamin Mendy and Saber Khelifa were also included in the starting XI by Anigo.
Nuri Sahin recovered from an ankle problem to feature in the Dortmund line-up as Klopp handed starting berths to youngsters Marian Sarr and Erik Durm.
Dortmund took the lead after just three minutes, left-back Durm playing an influential role as he played in Lewandowski with a deft pass, with the Poland striker making no mistake as he coolly lifted the ball over Steve Mandanda.
However, the visitors' hopes of qualification were dealt a blow 11 minutes later when Diawara headed into an empty net after Khelifa had turned Dimitri Payet's superb free-kick against the crossbar.
Dortmund continued to dictate an extremely open game, though, but struggled to create many meaningful chances. Reus went closest just after the half-hour mark when he blazed over the bar following a swift counter-attack.
But the German outfit's fortunes turned shortly after as Payet was dismissed for a second booking in a matter of minutes after referee Marijo Strahonja ruled that the winger had dived in an attempt to win a penalty from a challenge with Sahin.
Marseille remained a threat despite their numerical disadvantage, however, with Andre-Pierre Gignac forcing Roman Weidenfeller into action before Reus spurned another opportunity at the other end prior to the interval.
Anigo's men rode their luck for much of the second period, and they were fortunate not to fall behind on two separate occasions, Reus hitting the post shortly after Mandanda had produced a brilliant far-post save to keep out Jakub Blaszczykowski's header.
Dortmund should have re-taken the lead in bizarre fashion after 66 minutes when Lewandowski intercepted Mendy's backpass, only to hit the side netting after rounding Mandanda.
Klopp's men refused to let up as they heaped further pressure on the Marseille defence, Reus somehow missing the target from point-blank range with the goal at his mercy.
And Dortmund were then denied a penalty in the closing stages after Mandanda collided with Lewandowski, but this proved immaterial as Grosskreutz's effort from the edge of the area snuck into the bottom corner to ensure their progression.
|Strootman: Totti could play for another five years|
|Saul: United target Griezmann important but no one is above Atletico|
|Strootman always knew he would extend Roma contract|
|Iniesta refuses to commit to Barcelona|
|Higuain: I have affection for Real Madrid rival Ramos|
|AFC Champions League Review: Al Ain hit six against Esteghlal as Al-Ahli defeat Al-Ahli|
|Eintracht Braunschweig 0 Wolfsburg 1 (0-2 agg): Vieirinha seals Bundesliga survival|
|Buffon deserves Ballon d´Or for current form, not past achievements - Chiellini|
|I hope he calls it a day - Adams urges Wenger not to spoil Arsenal reign|
|Allegri not worried by Juve final record|
|Another promotion campaign daunting for defeated Stam|
|The pundits wrote us off - Wagner hails Huddersfield´s fairytale promotion to Premier League|
|The night Valverde embarrassed Barcelona|
|Managing egos, sorting the defence and playing the Barca way - Valverde´s Camp Nou challenges|
|Valverde named new Barcelona boss|
|Huddersfield Town 0 Reading 0 (aet, 4-3 pens): Ward the hero as Wagner´s men go up|
|Chiellini: Juve better than 2015 Champions League final loss|
|Strootman signs new five-year Roma deal|
|Pellegrino leaves Alaves after Copa final defeat|
|Bye for now - Hart departs Torino after loan spell|
|BREAKING NEWS: Ter Stegen agrees Barcelona renewal until 2022|
|Bartra feared for his career after Dortmund bus attack|
|Dortmund confirm knee ligament damage for Reus|
|Calm down - Mendy cools talk of City move with Paris video|
|AC Milan losing patience over Donnarumma|
|Terry eyes Wembley return as a manager|
|Coman pondered Bayern exit|
|Four fans die after stampede ahead of Honduran final|
|Mijatovic magic, Zidane heartache - Real Madrid and Juventus´ 1998 Champions League final|
|Moses is not a cheat - Conte|
|MLS Review: Atlanta too good for New York City, Dallas draw|
|Totti could´ve played for any big club – Ramos hails Roma great|
|Wenger: FA Cup win my presentation for new deal|
|I´m crazy about returning to Spain – Nolito eyes City exit|
|Roma defender Emerson suffers anterior cruciate ligament injury|
|Zenit sack Lucescu after missing out on Champions League|
|This was probably my last game for Benfica - Ederson hints at Man City move|
|Empoli relegated as Crotone beat Lazio to secure Serie A survival|
|Lorient 0 Troyes 0 (1-2 agg): Goalless draw sees visitors promoted to Ligue 1|
|Dzeko´s 29 goals claim Serie A Capocannoniere|
|Inter 5 Udinese 2: Perisic stars in crushing victory|
|Ausilio confirms Manchester United interest in Perisic|
|Totti: I´m not ready to say it´s over|
|Totti is not normal - De Rossi emotional after Roma icon´s farewell|
|Twenty-five seasons, 307 goals, one incredible legacy – the numbers behind Totti´s remarkable career|
|Sampdoria 2 Napoli 4: Comprehensive win not enough to snatch second place|
|Roma 3 Genoa 2: Perotti seals Champions League berth in dream farewell for Totti|
|Leave him alone! - Montella shrugs off Donnarumma error|
|I didn´t want to leave Real Madrid - Ronaldo|
|The offside rule is crazy - Cahill hits out at Sanchez FA Cup goal|
|I think Rooney wants to leave Manchester United, says Robson|
|Cagliari 2 AC Milan 1: Pisacane late show seals fitting Stadio Sant´Elia farewell|
|Inter announce Palacio departure|
|Courtois ready to sign new Chelsea contract|
|Everyone wrote me off - Critics inspired Mertesacker before Arsenal triumph|
|Emery never feared the sack at PSG|
|Barcelona future not in my hands – Paco Alcacer|
|Varane wants to see Mbappe alongside history-maker Ronaldo|
|Iniesta: I needed Busquets´ help to lift the Copa del Rey trophy!|
|Man United capable of anything - Lingard eyes glory next season|
|Freiburg´s Grifo signs Borussia Monchengladbach deal|
|Verratti expects to be at PSG next season amid Barcelona rumours|
|Coquelin: FA Cup win was for Wenger and we want him to stay|
|Ibrahimovic wanted by ´many clubs´, but he´ll stay in Europe - Raiola|
|Matuidi unsure about PSG future amid Man United links|
|Al-Khelaifi certain Emery will stay at PSG|
|MLS Review: Galaxy win Clasico, Sporting KC beaten|
|He will be at the Wanda Metropolitano – Atletico hint at Griezmann stay|
|Mexico 1 Croatia 2: Hernandez breaks record in surprise loss|
|Mexico 1 Croatia 2: Hernandez breaks record in surprise loss|
|Luis Enrique hails ´extraterrestrial´ Messi|
|Every player wants to play more – Fabregas cagey on Chelsea future after final omission|
|Tuchel hopes to continue as Borussia Dortmund boss|
|Kompany adamant Stones ´has everything´|
|People talk too much about China - Costa would only leave Chelsea for Atletico|
|Conte clear-headed for close season after Chelsea´s Wembley woe|