The Portuguese side was on the brink of being eliminated from the last 16 before a late strike saved it at the end of a packed match.Benfica left it until stoppage-time to rescue its chance at reaching the last 16 of the Champions League, beating Anderlecht 3-2 on Wednesday.
Olympiakos went into the Group B clash three points ahead of third-placed Benfica, but the Greeks' late defeat at Paris Saint-Germain allowed the Portuguese side to move level with them on points but behind on head-to-head record.
Jorge Jesus' men trailed after Chancel Mbemba's 18th-minute opener but hit back through Nemanja Matic 11 minutes before the break, with Mbemba's own goal handing the visitors the advantage early in the second half.
Massimo Bruno struck with an excellent finish 14 minutes from time to move Anderlecht level, only for substitute Rodrigo to provide a dramatic twist with a last-gasp winner.
After a quiet start, the first chance fell to Anderlecht in the 17th minute. Aleksandar Mitrovic cut a pass back to the edge of the area for Bruno, but Artur tipped it over the bar.
The goalkeeper could do nothing to prevent his side falling behind a minute later, though.
Fabrice N'Sakala lofted a pass into the area from deep for Mbemba and after his first touch ricocheted back off Luisao, the Congolese defender slotted under Artur.
Mitrovic saw a goal disallowed for offside just before the half-hour mark, and Benfica made the most of it four minutes later.
Matic nodded Enzo Perez's left-wing free kick past Silvio Proto, but Cheikhou Kouyate nearly restored the hosts' lead with the next attack as he headed a cross narrowly over.
Benfica needed only seven minutes to take the lead in the second half. Nicolas Gaitan latched on to a through ball in the area and after producing a clever turn, he hit a low shot that was deflected in by Mbemba.
After taking the lead, Jesus' side became more inclined to hit Anderlecht on the counterattack and Lima went close to scoring a third as he stroked a shot just over with the outside of his foot following Perez's cutback.
Bruno grabbed the equalizer from a narrow angle in the 76th minute, but Rodrigo had the last word, applying a cool finish after racing clear in stoppage time.
Benfica now await the visit of PSG in its final, decisive group game.