A dramatic equaliser from Zenit St Petersburg four minutes into added time meant holders Chelsea failed to top their Champions League group.
Substitute Magomed Ozdoev scored a stunning half-volley from the edge of the box after Chelsea had come from behind to lead 3-2 with minutes left.
Timo Werner scored in both halves and also set up Romelu Lukaku after Zenit had come from 1-0 down to lead 2-1.
But Ozdoev’s strike meant Chelsea finish behind Juventus, who beat Malmo.
Thomas Tuchel’s side – whose only defeat of the group stages came in Turin when they lost 1-0 to Juventus – made the perfect start, Werner reacting to poke in the opener within three minutes.
Two goals in quick succession from Claudinho and Sardar Azmoun saw Zenit go in front at the break, before Werner’s one-two with Ross Barkley helped tee up Lukaku for Chelsea’s second.
Werner, who was a threat for Chelsea throughout, showed composure to make it 3-2 when substitute Christian Pulisic played him in with five minutes remaining.
But Ozdoev’s stunning stoppage-time strike ensured Juventus topped Group H, while Zenit finished in third and will go into the Europa League play-offs in February.