European champions Real Madrid suffered a first defeat of the season as RB Leipzig strengthened their hopes of making the Champions League last 16.
Croatia defender Josko Gvardiol headed the hosts ahead before France forward Christopher Nkunku doubled the lead.
Vinicius Jr reduced the deficit but ex-Chelsea forward Timo Werner made sure of a memorable win for RB Leipzig.
Real, who had already qualified for the knockout stage, scored a late second with a penalty from Rodrygo.
With Celtic holding Shakhtar Donetsk in Glasgow in the other game in Group F, second-placed RB Leipzig have nine points, three more than Shakhtar who are in third spot.
Shakhtar host RB Leipzig in Poland on 2 November (17:45 BST).