Toni Kroos put the hosts ahead after 14 minutes with a well-taken, side-footed finish from Vinicius Junior’s pass
Karim Benzema doubled the advantage before half-time, slotting in his 10th league goal of the season from David Alaba’s cross.
Substitute Radamel Falcao headed in with 13 minutes left but Rayo could not find an equaliser and remain sixth
Victory moved Carlo Ancelotti’s side two points clear of Real Sociedad, although Sevilla will join them on 27 points if they defeat Real Betis on Sunday (20:00 GMT).
Benzema had several chances to put the hosts’ beyond reach, while Vinicius was unable to finish after a superb run and Marco Asensio was also denied at close range.
They were almost punished for their profligacy in added time but Kroos produced a goal-line clearance and Thibaut Courtois tipped a follow-up shot from Unai Lopez over the crossbar.