The Portuguese attacker missed a number of chances throughout the match but added gloss to the win with a stoppage-time penalty strike.
The Blancos dominated most of the match, and although Ronaldo missed a host of chances he secured the win in second-half stoppage time as he buried a penalty after Di Maria scored the opener.
Carlo Ancelotti brought in Alvaro Morata and Pepe among five changes to his side, while Gareth Bale was named on the bench after a spell out with a thigh injury.
Malaga also made five alterations from the defeat to Osasuna before the international break, with coach Bernd Schuster receiving a boost as club captain Weligton was able to make his first start of the season following a collarbone problem.
Unsurprisingly, the home side was the dominant force throughout the first half, but struggled to find the finishing touch despite creating several good opportunities.
Ronaldo went close twice in the opening 20 minutes as he first struck the crossbar after cutting into the area from the left, and then stroked wide of the goal when one-on-one with Willy Caballero.
Caballero was Malaga's savior with just under 10 minutes left of the first half as Morata connected with Marcelo's left-wing cross, only for the Argentine goalkeeper to stick out an arm to keep the score level.
Real may have wasted numerous chances in the first period, but the team's luck changed less than a minute after halftime as it took the lead in fortuitous fashion.
Di Maria cut in from the right and curled a cross into the danger area from a deep position, but Ronaldo could not reach it and the ball bounced past the static Caballero to break the deadlock.
Real continued to carve out chances despite Malaga's resolute defense, and Ronaldo almost got on the end of a corner after Caballero had parried his attempted cross wide.
Caballero again frustrated Ronaldo with 17 minutes remaining as he saved an excellent free kick from the Portuguese.
Bale then entered the fray a few moments later before making a telling contribution.
Ronaldo missed two more chances late on but, after Bale was tripped by Weligton in the area, the former Manchester United man stepped up and fired past Caballero to secure three points.