The Spanish giants produced a memorable 45 minutes to defeat Manuel Pellegrini's men after being 2-0 down at half-time, and are now favourites to reach the quarter-finals
After 10 minutes Sergio Sanchez rose highest to head Santi Cazorla's header into the net before the former Villarreal playmaker grabbed his second assist of the game when Martin Demichelis beat goalkeeper Iker Casillas to the ball to give his team a comfortable lead.
However, two goals in two minutes from Sami Khedira and Gonzalo Higuain saw the home team draw level before Karim Benzema grabbed the winner with 12 minutes left to play.
Both sides made cautious starts to the game, yet on 10 minutes Malaga shocked the hosts by taking the lead. Cazorla whipped an inviting corner into the box from the left where Sanchez was on cue to firmly head the ball past Casillas from six yards out - his first goal for the Andalusian outfit.
The second goal of the game fell to the visitors on 29 minutes, much to the dismay of the home support. Again, the assist was provided by Cazorla who curled his corner into the danger area with Demichelis doing well to beat a lacklustre Casillas to the ball to plant his header into the back of the net and give Manuel Pellegrini's side a deserved half-time lead.
The home side made a determined start to the second period and grabbed their just rewards in the 68th minute when a rare Khedira strike made it 2-1. The German international midfielder's driving run saw him power past the Malaga defence before smashing the ball beyond Cabellero for his second goal in a Madrid shirt.
Amazingly, two minutes later Mourinho's men were level after some shocking defending by Sanchez. The former Sevilla man's weak backpass was intercepted by Higuain who rounded the keeper before slotting home from a tight angle to put his side right back in the tie.
The comeback was complete in the 78th minute when Ronaldo's clever flick fooled the Malaga backline as Benzema ran clear to slide the ball past the helpless Cabellero and give his team a 3-2 win on the evening.
The two sides meet again on January 10 at La Rosaleda, with a quarter-final place in the tournament at stake.