Real Madrid were stunned by La Liga's bottom club Rayo Vallecano, who kept their slim hopes of survival alive.
It is the first time Real have lost to a team bottom of the league since 2004.
Boss Zinedine Zidane made eight changes to his team as he continues to experiment with his third-placed squad, who have little to play for.
Adrian Embarba scored the only goal for Rayo from a video assistant referee-awarded penalty following a Jesus Vallejo foul on Javi Guerra.
The referee did not initially award a penalty. Real broke and Gareth Bale had a shot saved before the referee viewed the incident on a screen and gave a spot-kick.