Chelsea thought they had done enough to win Group H but a screaming volley scored by Magomed Ozdoev in the fourth minute of stoppage time knocked them from top spot.
Thomas Tuchel’s team were already qualified for the last 16 before they travelled to Russia but they will progress as runners-up behind Juventus, and will be drawn against one of the group winners, after they were held to a draw by Zenit St Petersburg.
Timo Werner opened the scoring after only 83 seconds and thought he had the winner when he grabbed a second in the 85th minute to make it 3-2.