Los Colchoneros fell behind early on but staged a comeback against their city rivals, who ended the contest with 10 men.
However, the Portuguese forward did better in the 14th minute as he headed home Mesut Ozil's corner from near the penalty spot.
© AP Photos
Atletico, who had been struggling to hold possession, threatened to equalise just three minutes later when Gabi shot from 25 yards out after being teed up by Arda Turan, but his effort went over the Real crossbar.
Diego Simeone's side grew in confidence as the first half progressed and restored parity in the 35th minute when Radamel Falcao sent Diego Costa through on goal to shoot past Diego Lopez from just outside the Real penalty area.
Real were unlucky not to go into the break with a one-goal lead as Ozil's strike from the edge of the Atletico box hit the post on 43 minutes.
Los Blancos were once again denied by the frame of the Atletico goal in the 69th minute, this time Ronaldo watching his free kick rattle the post as Michael Essien failed to tuck in the rebound from just yards out.
Those chances came back to haunt the former Spanish champions in the eighth minute of extra time when Atletico surged ahead, Miranda heading home Koke's cross from close range after beating Lopez to the ball.
Real poured forward to grab the equaliser as the extra time progressed, but Courtois made two good saves to keep out Gonzalo Higuain and Ozil.
Things turned ugly with six minutes left on the clock when Ronaldo was sent off for a second bookable offence, leading to a brawl between the two sets of players.
Gabi was dismissed in the 125th minute for picking up his second yellow card of the match, but that did not deter Atletico from winning against their city rivals for the first time since 1999.