Ronaldo made it 3-0 in the early stages of the second half, but two Jonathan Viera penalties cut the score to 3-2 with 55 minutes on the clock.
Rayo continued to press in the latter stages, but Madrid held on to claim a vital three points against their rivals.
Read how it all unfolded in Sports Mole's minute-by-minute live commentary of the action below.
RAYO VALLECANO: Ruben; Arbilla, Tito, Martinez, Galvez; Adrian, Trashorras, Saul, Falque; Lass, Viera
REAL MADRID: Lopez; Carvajal, Pepe, Ramos, Coentrao; Alonso, Modric; Di Maria, Bale, Ronaldo; Benzema