The Rossoneri needed either a single point to guarantee a knockout spot, or to avoid losing 2-0, 3-1, or by more than two goals to secure a berth via the Europa League's tiebreaker rules. However, goals from Pape Abou Cisse and Kostas Fortounis, as well as a Cristian Zapata own goal, sealed a disastrous early exit for the Italian side.
After a nervy, error-strewn first half in Piraeus, Cisse nodded home on the hour mark after a penalty-box scramble to ramp up the home atmosphere and give the Greek side a fighting chance of progressing.
The visitors suffered a terrible slice of luck nine minutes later, as a huge deflection off Zapata saw the ball loop over Pepe Reina from 15 yards to put Olympiacos in the driving seat.
Milan nearly saved themselves when Zapata netted at the right end, but an 81st-minute penalty from Fortounis, awarded for a debatable foul call, was ultimately the killer blow.
The Italian side, along with manager Gennaro Gattuso, will now face increased scrutiny after failing to progress from the group stage of a European competition for the first time since 2001.