Los Blancos were heading out at the Santiago Bernabeu after their former striker Alvaro Morata had struck in the first half for Atletico.
But Rodrygo's fantastic solo effort forced an extra half-hour in the Spanish capital, before Karim Benzema and Vinicius Junior completed the turnaround for the hosts.
Carlo Ancelotti's side joins Barcelona, Athletic Bilbao and Osasuna in the semi-finals, but Diego Simeone's visitor will rue missing out on the last four.
Despite an early command of the game, it was the host which went behind in the 19th minute when Morata tapped in Nahuel Molina's square ball from close-range.
Madrid blew a big chance to level matters on the half-hour mark when Eder Militao was caught off-guard by a free-kick delivery and botched a simple header.
Matters went from bad to worse for Ancelotti's side too after they were forced into a substitution before the break thanks to an injury to Ferland Mendy.
Los Blancos were forced to wait for much of the game to find their response, but their patience paid off in the 79th minute when Rodrygo skipped past four Atletico players before prodding past Jan Oblak at his near post.
Tempers started to fray between both rivals in extra-time, with Stefan Savic dismissed in the 99th minute after two yellow cards in quick succession.
Gifted a man advantage, Madrid seized the chance with Benzema able to guide Vinicius' rushed effort in past Oblak, before the Brazilian signed off the game with a finish of his own, tucked away after a fine run in off the left wing.