Pablo Fornals scored a superb late goal for Villarreal as they won at the Bernabeu for the first time to load more pressure on Real Madrid boss Zinedine Zidane.
Real edged the first half and Gareth Bale had a header ruled out for offside, before Cristiano Ronaldo’s free-kick was tipped onto the bar.
However, the visitors improved in the second period and deservedly went ahead after breaking at pace from a Real corner.
Denis Cheryshev found Enes Unal, whose shot was saved by Keylor Navas – but Fornals then chipped the stranded keeper from 20 yards.
Fourth-placed Real Madrid, who won last season’s La Liga title and the Champions League, remain 16 points behind leaders Barcelona – and that gap could increase when Barca visit Real Sociedad on Sunday
Zidane’s side’s Champions League spot for next season is looking perilous – they now sit only one point above Villarreal, who move up to fifth.
Ronaldo, who has only scored four La Liga goals this season, missed several chances to score but had a strong penalty appeal turned down in the first half when he was clipped just before shooting at keeper Sergio Asenjo, who put in an excellent performance.