Down 2-1 entering the second half, goals by Cristiano Ronaldo, Luka Modric, and Gonzalo Higuain silenced a strong first half by Mallorca and Madrid extended its eight-game unbeaten streak against Los Bermellones.
Higuain netted two goals, one to tie the game 1-1 in the 14th minute, and the other to put away Mallorca in the 57th.
Modric, making the most of his limited playing time at the Bernabeu this season, scored his second goal of year.
Ronaldo scored his 27th La Liga goal of the year with a header that flew across the box and landed in the left corner of the net after a cross from Mezut Ozil in the 51st minute for a 2-2 tie. Ozil now has nine assists on the season.
Karim Benzema came in for Alvaro Arbeloa in the 46th minute and netted the game's last goal during extra time for a 5-2 score.
Los Bermellones made the most of their two first half corner kicks with two goals in the first 21 minutes.
The first came after midfielder Giovani Dos Santos laid out a corner kick cross that Emilio Nsue converted into a powerful header at the top of the box for the match's first goal in the sixth minute.
In the 21st minute, Alejandro Alfaro’s headed in a deflection by Pedro Bigas for a 2-1 lead, but Mallorca couldn’t withstand Madrid’s quick striking and set play midway through the second half.
Mallorca last beat Los Blancos in 2009.
Madrid now has two weeks off between La Liga games, and next face Real Zaragoza on March 30.