Missed chances and a controversial refereeing call were ultimately behind the result, the Blues' first after Emma Hayes season-ending move to the USA job was confirmed.
Olga Carmona struck an early deflected effort for Los Blancos before Niamh Charles and Sam Kerr turned the game deservedly in the Blues' favour - only for Jessie Fleming to be harshly pulled up for a late tackle to concede a penalty which Carmona buried late on.
Despite a strong start, Chelsea fell behind when Ann-Katrin Berger's clearance failed to find a blue shirt and Real launched the first shot of the game to earn a fortuitous opener.
Carmona's effort may well have been threatening Berger's left-hand post, but instead took a wicked deflection off Millie Bright to fly in on the beaten goalkeeper's right.
Chelsea settled down fairly quickly despite Real growing in confidence but struggled to get star striker Kerr into the game until later in the half. Charles and Fleming combined well down the left to find the Australian, but a cross into the six-yard box went unmet before being cleared as Fran Kirby lingered.
Kirby worked well in the hole behind Kerr, popping up time and again and feeding her teammate on the half-hour mark for a shot well saved at Misa Rodriguez's near post.
The Blues upped the ante as the half went on and levelled through Charles, who had threatened all game with her runs and delivery but this time got on the end of a fine Ashley Lawrence cross to head home.
Chelsea needed more of the same after the break and the game broke into an end-to-end spell which saw Jess Carter's superb through ball send Kerr through one-on-one, only for Rodriguez to pull off a smart stop.
Lauren James entered the fray after an hour to turn the visitors' dominance into three points, however her first contributions were to overhit a through ball into touch before a lazy strike from range flew over the bar.
Chelsea could however rely on Kerr to appear when the moment demanded it, this time directing a bullet header into the net for 2-1 after 74 minutes from a pinpoint cross by the fantastic Charles.
— DAZN Football (@DAZNFootball) November 15, 2023
Alas, Madrid found their way back into the game when Fleming's clumsy tackle was wrongly adjudged to be inside the box by Danish referee Frida Klarlund. A foul it may well have been, albeit with minimal contact, but the decision to award a penalty proved to be the ultimate factor behind the result - and wrongly so.
Carmona tucked away the spot kick to leave Chelsea with just over ten minutes plus stoppage time to right that wrong, and they came closs through Johanna Rytting Kaneryd's dipping volley that was well saved.
James then sprung into life. First, hitting the bar from range before Fleming slotted the rebound wide and then teeing up Kerr for a run on goal which Oihane Hernandez expertly dealt with.
There was still time for more drama in the 96th minute as Charles popped up at the far post to net what looked like a winner, and yet the flag quickly went up to call out the offside Kerr for interfering with play.