Juventus just about edged a topsy-turvy Group A encounter with Olympiakos to put themselves in a strong position to qualify for the knockout stages of the Champions League.
Andrea Pirlo, making his 100th appearance in Europe's premier club competition, lit the touchpaper with his goal from a trademark free-kick, but Alberto Botia's header restored parity moments later.
After an hour the destiny of the points swung towards the Greek champions briefly as Delvin Ndinga caught Juve cold with a headed goal.
Fernando Llorente and Paul Pogba then orchestrated the game's second comeback with the Spaniard forcing Roberto to put through his own net before setting up his French team-mate to score.
Juve had done enough to secure their 3-2 win but were thwarted in their last attempt to extend the margin of victory as Arturo Vidal missed a penalty deep into stoppage time.
Massimiliano Allegri's side are now level on six points with Olympiakos ahead of meetings with group leaders Atletico Madrid and fourth-placed Malmo.
Juve pushed hard for the opener and twice went close before Pirlo delivered the goods.
Pogba warmed Roberto's palms with a shot from distance and only speedy reflexes from the Olympiakos goalkeeper kept Claudio Marchisio's thunderbolt from hitting the back of the net.
There was no stopping Pirlo in the 20th minute, though.
After Botia fouled Pogba within shooting range, the veteran playmaker coolly stepped up to steer the ball over the ball and into the top corner.
The Greeks hit back immediately and were level in the 23rd minute thanks to Botia, who rose highest to head Alejandro Dominguez's cross beyond Gianluigi Buffon.
Juve went all out to restore their lead with Leonardo Bonucci, Stephan Lichtsteiner and Alvaro Morata all taking turns to give Roberto food for thought.
Olympiakos were always a threat, however, and Kostas Mitroglou's fearsome drive was only kept from hitting the target by a brave block from Giorgio Chiellini.
Marchisio, connecting with a wonderful cross from Kwadwo Asamoah, volleyed wide from close range as half-time drew closer.
Juve appeared sluggish at the start of the second half and were almost caught cold as Luka Milivojevic twice took aim at Buffon's goal, Bonucci making the required blocks on both occasions.
The Italian champions did not heed the warning and fell behind on the hour mark as Ndinga nodded Giannis Maniatis' cross home to give the visitors the lead.
Juve were staring at a premature exit from the competition so responded enthusiastically, substitute Llorente drawing an own goal from Roberto with his tricky header.
By the end of the 65th minute the Bianconeri were leading the game once again.
Barely 90 seconds after forcing the equaliser Llorente had picked out Pogba on the edge of the box and the young France international gratefully rifled the ball beyond Roberto and home.
The dust took a while to settle and the next team to create an opportunity were Olympiakos, who went very close to equalising as Omar Elabdellaoui smashed wide from a great position.
Scoring a fourth goal was of the essence for Juve if they were to swerve the embarrassment of being pegged back a third time, and Carlos Tevez nearly provided it with a rasping drive in the last five minutes.
What followed might have been an episode to regret had the Italians not managed to re-establish their lead.
After Milivojevic impeded Tevez in the box, Chilean midfielder Vidal saw his powerful penalty plucked out of the air by the quick-thinking Roberto.