Javier Saviola put the hosts ahead shortly after the half-hour mark, before Sacha Kljestan pulled the Belgians level out of nothing before the break.
Saviola then saw his penalty saved four minutes into the second period, after Cheikhou Kouyate had been dismissed for a second yellow card, but made up for it by restoring Olympiacos' lead nine minutes later.
Substitute Vladimir Weiss had a chance to all but seal qualification in the 72nd minute, but found Silvio Proto in inspired form as the goalkeeper kept out another spot-kick, before Fabrice N'Sakala became the second Anderlecht player to be given his marching orders late on.
Remarkably, a third penalty was awarded and Proto dismissed for his foul on Weiss, and substitute Alejandro Dominguez kept his cool against stand-in keeper Aleksandar Mitrovic to wrap up the win.
The result sends the Greek side through due to their superior head-to-head record against Benfica, who triumphed 2-1 against Group C winners Paris Saint-Germain.
Saviola and Michael Olaitan came into the Olympiacos starting XI as part of four changes to the side that beat Asteras Tripolis 2-0 in the Greek Super League on Saturday.
Anderlecht, meanwhile, made just one alteration from their 2-0 victory over Waasland-Beveren in the Belgian Pro League at the weekend, with Luka Milivojevic replacing the suspended Massimo Bruno.
Olympiacos applied the early pressure, but failed to take advantage of two free-kicks from the edge of the penalty area.
Saviola and David Fuster exchanged passes brilliantly in the 32nd minute to set up a chance for the Argentine, who glanced his effort agonisingly wide.
However, he made up for that miss less than a minute later, firing a low left-footed effort into the bottom right-hand corner of the net after receiving the ball from Fuster once again.
But Anderlecht levelled six minutes later with their first attack of the match. A counter from an Olympiacos corner culminated in Dennis Praet squaring the ball to Kljestan, who was left with a simple finish from 12 yards.
Olympiacos were awarded a penalty just four minutes into the second half, with Kouyate shown a second yellow card for his handball in the area.
But the subsequent spot-kick was poor, Proto getting down to his left to keep out Saviola's strike with relative ease.
Saviola went from villain to hero nine minutes later by acrobatically getting the final touch to a Fuster strike and divert the ball beyond Proto to restore the hosts' lead.
Roberto had to be alert to deny Guillaume Gillet, before N'Sakala brought down Weiss in the area 18 minutes from time, handing the hosts a second penalty. But they failed to make the most of the chance once again as the Slovak was denied by Proto.
N'Sakala picked up his second yellow card in the closing stages and Proto followed him down the tunnel in stoppage time, with Dominguez completing the scoring from the spot.
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1