The Croatian scored a spectacular effort from long range as Jose Mourinho's halftime changes saw his side turn around a 2-1 deficit with three goals in five minutes
An unorthodox lineup featuring Pepe as a defensive midfielder did not have the intended effect for the home side, who struggled with the high ball as Malaga ended the first half in front through Emilio Nsue and Alejandro Alfaro, either side of a Gonzalo Higuain effort.
But Jose Mourinho's tactical and personnel readjustment at half time paid off almost immediately, as three goals in five minutes from Cristiano Ronaldo, Luka Modric and Higuain sent the hosts into a two-goal lead before the hour mark, an advantage that they would never relinquish.
Karim Benzema added a fifth at the death, as Madrid keep its hold on second spot in the table, moving four points clear of third-placed Atletico Madrid, which visits Osasuna on Sunday.
With Pepe pushed further forward, Raphael Varane returned to displace Raul Albiol in the centre of defence, while Jose Callejon made way for 20-year-old Alvaro Morata out wide.
Mallorca would make the brighter start to the match though, due in no small part to the enterprise of Giovanni dos Santos. The former Barca winger was at his best to beat his man and hang a cross towards the far post, where Nsue was waiting to head home the opener.
But Madrid was soon back down the other end of the pitch, and Higuain would force Dudu Aouate into an unconventional save with his chest from an odd angle.
Higuain would make no mistake on the quarter hour mark though, smashing into an open goal after Pepe had done enough to harness a Modric through pass and roll the ball into his path, despite suspicions of offside.
But six minutes later, Mallorca was back in front, when Dos Santos’ corner was flicked on by Pedro Bigas, and nodded in at the far post by the unmarked Alfaro.
The scoreline did not always reflect the tone of the match, as Mallorca spent large periods without the ball, but its stout defending managed to frustrate the home side.
However, Ronaldo nearly broke the resilience just before the half hour mark when his attempt from Morata’s layoff clipped the woodwork on its way out.
But Mallorca’s danger lay chiefly in its aerial threat, and it nearly gave Madrid another painful demonstration when dos Santos’ corner was nodded inches wide minutes before the interval.
Mourinho moved quickly to rectify the situation at the break, introducing Benzema and Mesut Ozil for Arbeloa and Morata, while shifting Ramos to right back and dropping Pepe into his natural central defensive position.
And the effect of his halftime readjustment was seen within moments, when Ozil’s corner was guided into the corner by the head of Ronaldo six minutes after the restart.
Barely a minute later, Modric sent the hosts into the lead for the first time with a sensational swerving first-time strike from 25 yards out that left Aouate with absolutely no chance.
The onslaught was not done, as almost straight from kickoff, Ozil meandered to the byline and cut back for Higuain to turn home Madrid’s fourth goal.
By the time the dust had settled, the only question remaining in the game was how many goals Madrid would score with Mallorca completely floored by the ruthless turnaround.
Higuain, Ozil and Ronaldo all spurned chances in the second half, but the fifth goal would eventually arrive at the death when the Argentine squared to Benzema, who made no mistake from barely a yard out.
And that served as the last kick of the game, as a day of experimentation for Mourinho ended successfully, and left him with plenty to ponder for his side's upcoming European clashes with Galatasary.