two down just after the half-hour, mathieu valbuena's 87th-minute winner completed a dramatic comeback and secured the french club's last-16 berth.
olympique de marseille are through to the uefa champions league round of 16 as group f runners-up thanks to a dramatic comeback win at borussia dortmund.
the hosts had an outside chance of qualifying themselves and made a vigorous start, building a 2-0 lead through jakub błaszczykowski and a mats hummels penalty. the nature of their task meant no amount of goals was going to suffice with olympiacos fc beating arsenal fc, though, and marseille halved the deficit in first-half added time via loïc rémy.
andré ayew levelled the scores five minutes from time, but om were still going out until substitute mathieu valbuena stepped up to hit a superb 87th-minute winner and send the french club through.
obliged to secure a sizeable win, the home side wasted little time in getting forward and called steve mandanda into action with just two minutes gone when a deflected robert lewandowski cross span dangerously towards goal.
marseille countered with power and organisation, but dortmund's menace also increased, with mario götze allowed space to unleash a low shot before błaszczykowski made the 23rd-minute breakthrough, pouncing on lewandowski's knock down after sebastian kehl had headed on a long throw.
nine minutes later, it was 2-0, stéphane mbia's high boot catching kehl and allowing hummels to send mandanda the wrong way from the penalty spot, while also requiring antonio da silva to replace the injured midfielder. unfortunately for both teams, olympiacos were winning in greece, leaving dortmund staring at elimination and marseille needing to triumph to advance.
the german champions' intensity faded noticeably as the news from greece filtered through and om seized their chance, rémy heading in morgan amalfitano's far-post cross to reanimate his side's hopes. they came close to levelling shortly after the restart too, felipe santana nearly finding his own net from césar azpilicueta's delivery before mandanda saved from ilkay gündoğan at the other end.
lewandowski then had an attempt deflected wide, and the scrappy nature of that effort presaged a drop in clear-cut chances. marseille raised themselves for a late push, however, drawing level when ayew nodded in amalfitano's corner. they then sealed an incredible win three minutes from time when valbuena cut in from the left, tricked his way past gündoğan and arced an unstoppable shot beyond roman weidenfeller.