Substitute Douglas Costa scored a brilliant stoppage-time goal to give Juventus a 2-1 win away to Lokomotiv Moscow on Wednesday, which clinched their place in the Champions League round of 16 with two games to spare.
Juventus went ahead when Lokomotiv goalkeeper Guilherme allowed Cristiano Ronaldo's powerful free kick to squirm through his legs and Aaron Ramsey touched the ball over the line after four minutes.
Aleksei Miranchuk levelled eight minutes later for the Railwayman, scoring from the rebound after his own header hit the post. The game was heading for a draw until Costa played a one-two with Gonzalo Higuain, raced into the area and nutmegged Guilherme for the winner.
Juventus top Group D with 10 points, three ahead of Atletico Madrid who are away to Bayer Leverkusen later on Wednesday. Lokomotiv have three points and Leverkusen none, meaning Juventus can finish no worse than second.
On a rainy Moscow evening, Guilherme then atoned for his mistake by making two saves in quick succession from Higuain.
The Brazil-born goalkeeper was almost caught out after another Ronaldo free kick bounced awkwardly in front of him early in the second half but then made another brilliant save to turn away the Portuguese forward's powerful drive.
Far from outclassed, Lokomotiv nearly went ahead in the 78th minute but Joao Mario saw his shot cleared off the line by Leonardo Bonucci with goalkeeper Wojciech Szczesny caught out of his ground.
Sarri surprisingly replaced Ronaldo with Paulo Dybala in the 78th minute but the move paid off as Juventus took all the points thanks to an inspired moment from Costa.