Cristiano Ronaldo made both goals at the Rosaleda, setting the France forward up for a tap-in before putting the Welshman clean through on goal late on with a flick-on
Coach Carlo Ancelotti had found his future called into question after Los Blancos lost consecutive Liga games to Real Sociedad and Atletico Madrid in September.
But the European champions have been irresistible since then, winning every game they have played in all competitions and netting an incredible 59 goals in the process.
Karim Benzema opened the scoring early on at La Rosaleda after fine work by Cristiano Ronaldo, before Gareth Bale grabbed the crucial second late on with an excellent finish after latching on to Ronaldo's flicked header.
Former Malaga playmaker Isco was then harshly sent off for a second booking, before Roque Santa Cruz ensured Real would face a nervy last minute or so when he nodded home in stoppage time.
However, Ancelotti's side held on for a deserved three points that ensures they will end the weekend top of La Liga.
The two sides contested a lively opening to the game, with both goalkeepers forced into important saves inside the first quarter of an hour.
Ronaldo was the first to go close in the 12th minute as the Portuguese star fired straight at the outstanding Carlos Kameni from nine yards after a clever pass from Bale.
Malaga caught Madrid on the counter almost immediately after that chance, and their move ended with Iker Casillas tipping a Santa Cruz header on to the roof of the net.
The open nature of the match suited Real, though, and they eventually went ahead in the 18th minute, as Ronaldo exploded past Roberto Rosales down the left and saw his cross instinctively steered in by Benzema.
The shaky Casillas almost handed Malaga an equaliser shortly after, but the Madrid captain's blushes were spared by the post after he spilled Sergi Darder's long-range effort.
Bale should have doubled Real's lead in the 40th minute as he raced on to a Ronaldo throughball, but he could only shoot straight at the onrushing Kameni.
And the frailty of the visitors' advantage was highlighted shortly before the break as Duda struck the crossbar with an audacious 35-yard free-kick.
Real looked threatening again at the start of the second half, and Ronaldo almost doubled their advantage in spectacular style in the 54th minute, narrowly missing the target with an acrobatic scissor-kick.
The Ballon d'Or holder - who has scored 20 Liga goals this term - should have made sure of the points with 13 minutes to go but Kameni produced a stunning save to palm away his low drive after he had capitalised on a mix-up between Marcos Angeleri and Weligton.
Malaga almost made the most of that let-off as Santa Cruz tested the unconvincing Casillas from the edge of the area, but Bale raced on to Ronaldo's flick-on and fired home in the 83rd minute to make the points safe.
A harsh second yellow for Isco, who was given a rousing reception from the home fans as he left the pitch, and Santa Cruz's excellent header made it a tense ending, but the Madrid juggernaut rolls on.