Los Blancos took the lead in the ninth minute when Benzema slotted home from close range after Ronaldo’s header had crashed against the woodwork.
Malaga equalised just over nine minutes later as Rolan collected a cross from Keko and fired past Kiko Casilla, 1-1.
The visitors’ joy was short-lived as Los Blancos restored their lead three minutes later courtesy of a bullet header from Casemiro.
Ronaldo almost extended Real’s lead after 37 minutes but Roberto Jimenez produced a superb stop to keep out the forward’s powerful strike.
The score remained 2-1 to the La Liga champions at the break.
Malaga equalised in the 58th minute through Chory Castro’s close range effort, and left the home side shocked.
Real were awarded a penalty in the 75th minutes when Luka Modric was brought down in the box. Ronaldo saw his spot-kick saved but fired home the rebound.
Los Blancos managed to hold out for the final stages of the second half to secure a vital victory in their pursuit on FC Barcelona.