A solo effort from Federico Valverde on the stroke of halftime levelled the scores after Vedat Muqiri had stunned the home crowd by nodding the visitors ahead. Vinicius put the hosts in front before Rodrygo and Antonio Rudiger completed the rout.
Real returned to the top of the table, two points ahead of second-placed Barcelona.
"We knew they'd cause us issues, they defended well and scored from a set piece and it was difficult for us to gain a foothold," Real coach Carlo Ancelotti said.
"But we kept cool heads and had enough quality to go ahead in the game. We didn't play in the best way that we could've in the first half, but we were much better in the second."
A much-changed Real initially struggled to gain a foothold and sorely missed injured talisman Karim Benzema in attack throughout a below-par first half.
Muqiri, who was denied by Thibaut Courtois inside the opening 40 seconds, headed in unmarked at the back post after 35 minutes and it appeared the champions would go in trailing at the break for the first time this campaign.
That changed, however, in added time at the end of the half when Valverde ran the length of the pitch before firing home a left-footed shot from the edge of the box.
After the break the hosts monopolised the ball, but were fortunate when Antonio Sanchez fired wide from six yards out with the goal gaping on a rare foray forward from the Balearic Islanders.
Rodrygo’s mazy run fed Vinicius 18 minutes from time and the Brazilian forward netted for a fifth consecutive game to put Ancelotti's side in front, before Rodrygo, who capped off a delightful run with a perfect finish, and a first goal in Madrid colours for Rudiger added late gloss to the scoreline.