Marseille scored twice in the last five minutes to win 3-2 at Borussia Dortmund and take second place in Group F ahead of Arsenal's conquerors Olympiakos.
The French side had trailed their German rivals 2-0 but after Andre Ayew levelled things on 85 minutes, Mathieu Valbuena grabbed an unlikely win.
In Group E, Bayer Leverkusen's 1-1 draw at Genk meant Chelsea beat them to top spot with their win over Valencia.
Porto also went out after a goalless draw with Zenit St Petersburg.
With Arsenal already through, Marseille went into the final day in control of their own destiny in Group F, a point ahead of third-placed Olympiakos.
However, Jakub Blaszczykowski opened the scoring for the Germans and Mats Hummels added a second from the spot and, although Loic Remy pulled one back in first-half added time, with the Greek side on their way to a comfortable win over Arsenal, French prospects looked bleak.
But Ayew equalised with five minutes remaining before Valbuena snatched second place away from Olympiakos with a third goal with just two minutes left.
Porto had given themselves a chance of progressing from Group G when they won 2-0 at Shakhtar Donetsk in their previous match.
But the 2004 winners and Europa League holders could not find a way past stubborn Russians Zenit, who held on to second place.
Apoel, who are the first Cypriot team to progress to the knockout phase, qualify as Group G winners despite slipping to a 2-0 home defeat to Shakhtar.
Luiz Adriano, who had earlier missed a penalty, put the Ukranians ahead before Yevgen Seleznev added a second to set up his team's first Champions League win of the season.
Leverkusen knew that a victory in Genk would have been enough to seal top spot in Group E but they fell behind to a first-half goal from Jelle Vossen.
Eren Derdiyok pulled one back for the Germans, but Chelsea's comprehensive win over Valencia meant Bayer had to settle for second place.
Group H's top two was already confirmed before the final round of fixtures but first-placed Barcelona's second string played with plenty of style on the way to a comfortable 4-0 victory over BATE Borisov, who knew a win at the Nou Camp would have given them a chance of third place.
Pep Guardiola's outfield players had an average age of just 21.4 years but swept past the Belarus champions.
Sergi Roberto opened the scoring before half-time, before defender Martin Montoya added a second and winger Pedro added two more, one from the spot, after the interval.
Facing Plzen, second-placed AC Milan scored twice in the space of two minutes at the start of the second half through Alexandre Pato and Robinho.
But David Bystron halved the deficit before Michal Duris scored an injury time equaliser for the Czech team, who finish third.