A penalty from Adrian Embarba in the first half proved the difference between the two Madrid sides in a 1-0 victory vital to Rayo's hopes of staying in the Spanish top flight.
Sunday's three points saw them move off the bottom of the table at Huesca's expense, although Girona's win leaves them six point short of survival with just three games remaining of the 2018-19 season.
Madrid showed little sign of getting back into the match in the absence of Karim Benzema and went down to their neighbours in a result that had not been seen in a generation.
One must look back to February 1997, more than 22 years ago, to find the last time Rayo got the better of Real in La Liga.
On that occasions a solitary goal was also good enough to down the Merengue, with Ezequiel Castillo netting to inflict defeat on a side coached by Fabio Capello and which included the likes of Roberto Carlos, Fernando Redondo, Raul and Davor Suker.
Since then Rayo have failed to beat Madrid in league play, with just one further victory in the Copa del Rey to their name.
In January 2002 the Vallecas side managed a 1-0 win in the quarter final, second leg, having lost the opening clash in the Bernabeu 4-0 to a Blancos side including current coach Zidane.
Embarba's decisive spot-kick was eventually given via the aid of VAR and also marked a curious new high for the visitors.
Not since 2005-6 have Madrid seen so many penalty decisions go against, with no less than seven to date in this, the first campaign played utilising the new technology.
2 - Real Madrid have failed to score in consecutive games in all competitions for the first time with Zinedine Zidane as manager. Reflection. pic.twitter.com/mieJfHOrfU— OptaJose (@OptaJose) 28 de abril de 2019
And after failing to score midweek against Getafe Zidane has seen his team draw a blank in two straight games, the first time this has happened in either of the Frenchman's two spells on the Madrid bench.
Madrid remain in third place in La Liga, nine points behind Atletico and 18 shy of newly crowned champions Barcelona.