Emilio Nsue gave the visitors an early lead but Gonzalo Higuain levelled, before Alejandro Alfaro put Gregorio Manzano's side in front again before half-time.
Two smart substitutions by Madrid coach Jose Mourinho at the break gave Los Blancos the lift they needed and goals by Cristiano Ronaldo, Luka Modric, Higuain and Karim Benzema in the second half gave a dominant Madrid the three points.
Mallorca, currently occupying the last relegation place but fresh from two consecutive league wins, took a surprise lead on six minutes.
Giovani dos Santos reached the byline and delivered a high cross into the area which Nsue, beating Fabio Coentrao in the air, leaped to reach and head into the bottom corner beyond the reach of Diego Lopez.
Madrid were level eight minutes later. Modric shook off a defender before delivering a through-ball into the path of Pepe, who squared to Higuain, giving the Argentinian the opportunity to shoot into an empty net.
Mallorca's lead was restored in the 21st minute - and Madrid were again vulnerable to a cross into the box from Giovani.
This time the Mexican sent in a corner which was headed on by Pedro Bigas towards the far post and Alfaro helped it into the net with his head.
Madrid almost replied instantly. Kaka played Ronaldo in but the Portuguese, facing a slight angle, could only shoot over the bar.
Ronaldo missed another good chance on the half-hour, receiving the ball just outside the six-yard box but his effort went just wide of the top corner.
Scottish full-back Alan Hutton almost extended the visitors' lead before the break, but his header from a corner went just wide of the post, as Madrid showed more vulnerability from crosses.
Mourinho's response to an uninspiring first half from his side was to make a double substitution at half-time. Alvaro Arbeloa and Alvaro Morata were brought off for Mesut Ozil and Karim Benzema respectively, which saw Sergio Ramos switch to right-back and Pepe moved back into defence to partner Varane.
The impact was not immediate, with Bigas missing a great opportunity just after the restart - blasting an overhead kick over the bar - but the effects of the changes would soon kick in.
Ronaldo glanced a header from substitute Ozil's corner into the bottom corner to score his 350th career goal, put Madrid on level terms and mark the start of a five-minute goal glut.
Madrid then took the lead for the first time in the game thanks to a superb goal from Modric. The Croatian midfielder controlled a Mallorca clearance 30 yards from goal with one touch and then rifled the ball far into the top corner to leave goalkeeper Dudu Aouate with no chance.
Three minutes later Higuain added his second goal of the night, driving the ball home from close range after a ball across goal from Ozil to all but secure the points.
The Argentinian was denied a hat-trick late on when Auoate stuck out a leg to prevent his low shoot from going in, but he provided the assist for Benzema's injury time tap-in, which proved to be the last kick of the game.