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 (19:45 GMT).
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.
Have your say
More Sports Headlines
- Development of football in Ghana – A general industrial development perspective
- AL-SMITH: Have Nigeria’s Super Falcons lost their fear factor? Looks like it.
- Yusif Abubakar: Former Aduana Stars coach dies
- 'Be more serious!' - Suarez urges team-mate Dembele to focus
- AWCON 2018: Ghana coach Bashir Hayford sure of victory over Mali
- 2018 Coca-Cola Clubs Minigolf League: Nutterz Putterz set the pace
- Altitude forced Ghana to slow down in second half - Kwesi Appiah
- Zverev stuns world number one Djokovic to win ATP Finals
- Switzerland come back to stun Belgium and reach Nations League semis
- Mauritania seal historic Afcon qualification
- AWCON 2018: Five-star Zambia trounce Equatorial Guinea
- AWCON 2018: South Africa stun Nigeria in Group B opener
- Kane inspires England comeback to seal UEFA Nations League finals place
- 2019 AFCON qualifier: Jordan double gives Ghana victory over Ethiopia
- Give us spectacular goals, impressive set pieces - First Lady to Black Queens