Karim Benzema, who limped off late on, struck in the 13th minute to ensure there was no repeat of the forgettable 3-0 loss to CSKA Moscow that summarily ended a run of four successive triumphs.
Marco Asensio had chances to put the result beyond doubt before Thibaut Courtois made a crucial double save in stoppage time, Santiago Solari's men returning to winning ways in time for Thursday's (AEDT) Club World Cup semi-final clash with Kashima Antlers.
It heads to the United Arab Emirates two points shy of table-topping Barcelona, which visits Levante on Monday, and with clean sheets in three straight LaLiga matches for the first time since September 2015.
Madrid began confidently in its bid to move on from the CSKA shock as Lucas Vazquez cut inside from the right and slipped through Benzema for the French forward's first goal in six games.
Chances came and went soon after the opener with Emiliano Velazquez heading marginally wide from a corner, before Stole Dimitrievski foiled Asensio in a one-on-one.
Rayo was fortunate to avoid additional damage before the break, Toni Kroos' left-footed drive cannoning into the post.
Dimitrievski denied Asensio for the second time five minutes after the restart while Sergio Ramos had a header ruled out for a marginal offside call as Madrid's wait for a second stretched beyond the hour.
It was never able to completely put the match to bed against its 19th-placed visitor and, after Benzema hobbled off, it was Courtois' time to shine, the goalkeeper well-placed to block both Alex Alegria's overhead kick and Velazquez's follow-up in a panicked conclusion.