Juventus progressed to the Champions League last 16 after a Cristiano Ronaldo goal and a late header from substitute Alvaro Morata gave them a comeback 2-1 home win over Hungarians Ferencvaros on Tuesday.
With two games remaining, the result left Juve second in Group G on nine points from four matches, three behind leaders Barcelona who also booked a knockout-stage berth with a 4-0 win at Dynamo Kyiv.
Ferencvaros and Dynamo are level on one point and will vie for the consolation prize of joining the Europa League round of 32 after the winter break.
Juventus coach Andrea Pirlo said a tactical switch to attacking down the flanks instead of through the middle paid off in the second half.
"I think we were better in the second half, tactically," said the former Italy midfielder.
"Sometimes we tried too often to break through the middle while we should have played more on the flanks. It was important to win and qualify, we tried until the end and this is what I liked the most."
The Italian champions made heavy weather of the clash against Ferencvaros after beating them 4-1 in the reverse fixture, and they often looked lethargic against a packed visiting defence.
Paolo Dybala missed their best chance in the first half when goalkeeper Denes Dibusz blocked his close-range shot in the 15th minute and the home side were punished four minutes later by a quality goal.
Myrto Uzuni fired Ferencvaros ahead with a delightful touch which beat home keeper Wojciech Szczesny after Tokmac Nguen had shaken off two markers and clipped a perfectly weighed cross into the heart of the penalty area.
Ronaldo, who barely featured in the opening half-hour, had a goal correctly ruled out for offside before he equalised in the 35th minute with a sweet, left-foot shot from 20 metres which fizzed into the back of the net inside the near post.
Juventus pressed in the second half but it looked like they would have to settle for a draw and leave themselves with work to do in order to qualify after Federico Bernardeschi and Morata hit the woodwork.
However, a valiant performance by the visitors was undone in stoppage time as Morata's downward header from eight metres squeezed under Dibusz's body and over the line after a fine cross from the right by Juan Cuadrado.
Striker Olivier Giroud scored a dramatic last-minute winner as Chelsea booked their place in the last 16 with a 2-1 victory over Stade Rennais.
Sehrou Guirassy looked as though he had secured a point for his side with an equaliser minutes earlier, but Giroud profited from some poor Rennes defending to claim the win after Callum Hudson-Odoi had put the visitors in front in the first half.
Chelsea top Group E with 10 points from four games, level with Sevilla but ahead on goal-difference, after the Spanish side also claimed a late 2-1 victory in Russia against Krasnodar to seal their passage into the knockout stages.
"I'm very happy to qualify with two games to spare," said Chelsea manager Frank Lampard. "It was a really tough match, they're a very good team. Their recent form doesn't reflect how good they are, it was a tough hard-fought win."
The results: Group E: Krasnodar lost to Sevilla 1-2; Rennes lost to Chelsea 1-2.
Group F: Lazio bt Zenit 3-1; Borussia Dortmund bt Club Brugge 3-0.
Group G: Juventus bt Ferencvros 2-1; Dynamo Kyiv lost to Barcelona 0-4.
Group H: PSG bt RB Leipzig 1-0; Manchester United bt Istanbul Baakehir 4-1.