The visitors started positively but they came unstuck in the 23rd minute when Gonzalo Higuain tapped home the rebound after Raul Albiol's shot had been saved.
Los Blancos doubled their lead almost instantly as Angel Di Maria fired in from the angle.
Cristiano Ronaldo nearly added to his side's tally as they became more dominant, but his rasping effort went inches wide of the post.
The away side were soon in the ascendancy and they came close again just after the hour as Jose Mari's stinging shot rattled the crossbar.
It was Ronaldo's turn to smash the ball against the bar with his free kick in the 83rd minute before Michael Essien converted from close range soon after to make it 3-0.
The win was sealed in injury time as Luka Modric scored his first goal for the club with a powerful effort from long range.