The Portuguese collected a superb Gareth Bale cross at the back post and fired past Claudio Bravo in the 85th minute, almost immediately after Sergio Ramos had been sent off for a second bookable offence.
Gerard Pique had opened the scoring in a fiery Clasico with a superb header, only for Karim Benzema to equalise just after the hour mark with an instinctive volleyed finish.
The result sees Real move within seven points of La Liga leaders Barca, and the result will also provide a major boost to Atletico Madrid, who lie second.
DOWNLOAD HIGHLIGHT