The home side opened the scoring after 35 minutes when Riki found the back of the net, with that scoreline still standing at the interval.
Madrid improved in the second period, however, and were level 20 minutes from time when Kaka curled an effort into the top corner.
There was still time for late drama, as Gonzalo Higuain tapped home in the final minute to secure all three points for Madrid.
Read how it all unfolded in Sports Mole's minute-by-minute live commentary of the action below.
REAL MADRID: Lopez; Arbeloa, Carvalho, Pepe, Marcelo; Modric, Essien, Kaka; Di Maria, Higuain, Callejon