The home side went a goal down after just 17 seconds, but came back to record a comfortable win despite Angel Di Maria's second-half dismissal, largely thanks to the Portuguese
Madrid had lost to Levante last weekend and failed to beat Racing Santander in another disappointing result on Wednesday, but instead of reacting positively early on in this match, Jose Mourinho's men got off to the worst possible start as they conceded after just 17 seconds.
Rayo in Spanish can mean lightning and the goal like a bolt out of the blue for the home side as Michu pounced on the rebound after Iker Casillas had spilled Raul Tamudo's effort from outside the box.
It was the fastest ever goal from a visiting side at the Santiago Bernabeu and hardly the start Madrid were looking for after two very poor results in the last seven days.
It took a while for them to react, as well, and Rayo continued to look dangerous on the break.
Raphael Varane, in the side alongside Raul Albiol as both Pepe and Ricardo Carvalho missed out through injury, shot side for Madrid and Kaka - in for Mesut Ozil - also came close, but Lass almost shocked the home side as he fired over after 25 minutes.
Three minutes later, the other Lass, Diarra, was substituted as Mourinho sent on Ozil, and Madrid improved instantly.
The German tested Dani Gimenez in the Rayo goal shortly after coming on and seven minutes before half-time, Madrid levellled, when Kaka set up Ronaldo and the Portuguese fired through the keeper's legs.
That was 1-1 and it soon became 2-1 as Xabi Alonso and Sergio Ramos combined for Gonzalo Higuain to give the locals the lead on the stroke of half-time with a simple finish.
After the break, Jose Maria upended Kaka and Ronaldo converted from the spot to make it 3-1.
Michu then reduced the deficit as he fired home at the far post, even though Casillas pushed the ball out. Replays shows the striker's effort had crossed the line.
And it looked as if the visitors may make a real game of it as Di Maria handled and was sent off for a second bookable offence.
But Varane back-heeled to make it 4-1, before substitute Karim Benzema blasted a fifth and Ronaldo rounded off a comprehensive victory with his hat-trick seven minutes from time.