- Pau Torres (16' OG)
- Vinícius Júnior (48')
- Samuel Chukwueze (39', 80')
- José Luis Morales (70')
Carlo Ancelotti's side had been imperious as they thrashed rivals Barcelona 4-0 at the Camp Nou in the Copa del Rey semifinals on Wednesday.
Yet they could not build on that momentum as they fell to a defeat that left them on 59 points in second place and opened the door for Barcelona to go 15 points clear at the summit if they beat Girona on Monday.
Madrid host Chelsea on Wednesday in the first leg of their Champions League quarterfinal tie and Ancelotti admitted his team were not fully motivated on Saturday.
"It was hard for us to get the ball back, we tried to win it in their half, and we weren't balanced," he said. "That's the reason we conceded three goals.
"Every player had a lower level than normal. It was hard to have our motivation at 100%, the effort against Barca cost us. That's normal, this defeat hurts, but I don't like to talk about individuals.
"It doesn't change our mood for Wednesday, that will be a totally different game. Compared to last year in the league, our level has dropped."
Vinicius Jr restored Real's lead two minutes into the second half with a simple finish in front of the Villarreal goal for his ninth league strike of the season.
Quique Setien's side levelled again in the 71st minute when Madrid's defence failed to clear, allowing Jose Luis Morales to fire home from close range, with VAR overturning the initial offside decision.
Chukwueze scored his second 10 minutes from fulltime with a spectacular strike from the edge of the box into the top left corner to win the match for Villarreal and silence the home fans at the Santiago Bernabeu.
"It's a crazy goal," Chukwueze said. "It's a dream to score this goal and win here. I'm very happy for this game. The future is going to be much better. I have to take advantage of this moment and keep improving."
Villarreal, who climbed to fifth place in the battle for a Champions League spot, host relegation-threatened Valladolid next Saturday.
Information from ESPN's Alex Kirkland was used in this report.
- Javier Alberola Rojas