- Yeremy Pino (47')
- Gerard Moreno (63' Pen)
- Karim Benzema (60' Pen)
Yeremy Pino opened the scoring for Villarreal just after the break before Madrid levelled through Karim Benzema's penalty in the 60th minute, but parity lasted only three minutes as Moreno also fired home from the spot to secure the points.
Madrid stay second, level on 38 points with Barca who visit fourth-placed Atletico Madrid on Sunday, while Villarreal's third straight league win moves them up to fifth spot.
Madrid named a starting XI without a single Spanish player for the first time in the club's 121-year history.
Yeremy had the best chance of the first half after he was played through on goal by Moreno, but goalkeeper Thibaut Courtois was quickly off his line to block the shot.
Madrid almost struck against the run of play as Benzema bore down on goal alongside team mate Vinicius Junior with just Raul Albiol in their way, but the Villarreal defender showed all his experience to win back the ball and quash the opportunity.
Benzema also created a half-chance for Vinicius towards the end of the first half, but the Brazilian's shot from an acute angle was hit straight at goalkeeper Pepe Reina.
Villarreal did not take their foot off the gas after the break and the pressure told in the 47th when Moreno set Yeremy free to charge at goal and unleash a fierce shot into the net.
Madrid grew into the game following Villarreal's goal, with Benzema and Vinicius continuing to orchestrate the champions' attacking efforts.
Juan Foyth appeared to have kept Villarreal ahead with a heroic goal-line block to deny Benzema in the 56th minute but, following a VAR intervention, the referee awarded Madrid a penalty for handball by the defender in the build-up to his block.
The spot kick was expertly dispatched by Benzema but Villarreal were awarded a penalty of their own two minutes later when a falling David Alaba unluckily handled the ball.
Moreno converted after Madrid's protests had calmed down, sending Courtois the wrong way to put his side back in the lead.
Alaba will leave the Estadio de la Ceramica feeling hard done by after his outstretched arm inadvertently touched the ball as he attempted to soften the impact of his fall.
But Madrid coach Carlo Ancelotti agreed with the decision, telling reporters: "The two penalties were correct according to the rules so of course the referee has to respect it."
Substitute Arnaut Danjuma squandered a golden opportunity to seal the game for Villarreal in added time, missing an open goal with his effort from the halfway line as Courtois was stranded deep in opposition territory after going up for a corner.
Ancelotti acknowledged that his side had been outplayed by their opponents, saying, "We couldn't play at their level.
"We were bad, especially in defence. We tried to create but we were too open in midfield. We should have done more."
- César Soto Grado