Olympiacos secured progression into the Europa League knockout stages at AC Milan's expense thanks to a 3-1 victory in Athens.
AC Milan crashed out of the Europa League as Konstantinos Fortounis' late penalty claimed a 3-1 win for Olympiacos, sending the Greek side through to the knockout stages.
Gennaro Gattuso's men required just a point to secure progression from Group F, but they found themselves behind when Pape Abou Cisse headed in on the hour.
With Milan's defence rocking, Olympiacos grabbed a crucial second goal as Cristian Zapata deflected Guilherme's hopeful strike into his own net nine minutes later.
Zapata immediately made amends when he bundled the ball in at the other end to make it advantage Milan courtesy of their improved head-to-head record, but, after Ignazio Abate was penalised for holding onto Vasilis Torosidis, Fortounis kept his cool to book Olympiacos' place in last 32.
Olympiacos could have been ahead inside 10 seconds, but Pepe Reina got a vital touch to Miguel Angel Guerrero's scuffed shot.
Jose Sa was on form to deny Gonzalo Higuain, Tiemoue Bakayoko and Patrick Cutrone as Milan gained a foothold, though it was Olympiacos who broke the deadlock 15 minutes after the restart.
Reina was caught in no-man's land from a corner and, despite Higuain making a goal-line block, Cisse was on hand to head home the rebound. Reina atoned for his mistake with a brilliant save from Daniel Podence moments later, only for Milan's goalkeeper to be beaten again when Guilherme's shot looped in off Zapata.
But although the Milan defender more than made up for it two minutes later when his header trickled over the line, it was Olympiacos who had the final say.
Abate needlessly dragged down Torosidis and Fortounis duly sent Reina the wrong way from 12 yards to secure the hosts' first competitive win over the Rossoneri.
What does it mean? European misery for Milan
Milan started their Group F campaign with two successive wins, but a defeat and draw in their fixtures against Real Betis left them in danger of missing out and handed Olympiacos a lifeline that they were more than capable of taking advantage of. It means that Betis go through as group winners, with Olympiacos securing second place on goal difference.
Captain Fortounis makes no mistake
The pressure was on Fortounis when he stepped up from 12 yards, but the hosts' captain showed excellent composure to send Reina the wrong way and slot home into the bottom-right corner.
Abate's moment of madness proves costly
There was little need for Abate, one of Milan's most experienced players, to make a challenge on Torosidis, with the Olympiacos substitute having offered little threat to goal from the corner which led to the penalty.
While Olympiacos are back in domestic action against Lamia on Sunday, Milan get another two days of rest before facing Serie A strugglers Bologna on Tuesday.