Cristiano Ronaldo and Jose Mourinho were sent off as Atletico beat Real in extra-time at the Bernabeu to overcome their local rivals for the first time in 14 years.
Miranda's header in the 99th minute won it for Atletico. Ronaldo's header gave Madrid the lead after 14 minutes, but Diego Costa levelled 10 minutes before half-time.
Madrid struck the woodwork twice in the second half while Juanfran blocked a shot from Mesut Ozil on the line to force extra time.
Atletico goalkeeper Thibaut Courtois made two superb saves to keep his side in front.
Madrid's frustration told and, with Mourinho having been sent from the technical area during normal time, Ronaldo saw red in the 114th minute for kicking out at Atletico captain Gabi - who was himself dismissed in the frantic final minutes for a second bookable offence.