Goals from Mariano and Vallejo insured victory for Madrid, although a Villarreal stoppage time goal left "a bitter taste" for Los Blancos.
Real Madrid earned a fifth consecutive home win by beating Villarreal 3-2 in an open and entertaining game on Sunday in front of their lowest crowd for a league fixture this season.
Madrid got off to an ideal start when Mariano Diaz netted in the second minute after teenager Brahim Diaz had chased down Santi Cazorla but Villarreal hit back in the 11th when Gerard Moreno slammed the ball inside the near post from outside the area after Real midfielder Casemiro was dispossessed.
Madrid, got themselves back in front shortly before halftime when defender Jesus Vallejo stuck the ball into an empty net after a deflected shot from Marcelo, while Mariano struck again early in the second half to stretch his side's advantage.
Villarreal continued to threaten and after they missed several chances Jaume Costa pulled a goal back in stoppage time, while defender Xavier Quintilla had an opportunity to level in the final seconds of the game but missed the target.
Mariano: "We are happy with how we played"
"We enjoyed ourselves out there today but their goal at the end left us with a bitter taste," goalscorer Mariano told reporters. "They caught us out on the counterattack but overall we played well and are happy with how we played."
Madrid had sunk to a new low in a disappointing season with a 1-0 loss at Rayo Vallecano last week, which was their 10th league defeat this campaign, and on Sunday only 46,294 fans made it to the Bernabeu, which holds over 80,000.
There were tributes before kick off to former Real captain Iker Casillas, who is recovering in hospital after suffering a heart attack during training with Porto on Wednesday. Madrid players wore t-shirts before kick off saying 'Everyone is with you Iker' while fans held up a banner saying 'Madrid is with you, Stay strong Iker'.
Madrid are third in the standings on 68 points after 36 games and still have an outside chance of catching second-placed Atletico Madrid who have 74 after losing at Espanyol on Saturday. Champions Barcelona have 83 points after losing 2-0 at Celta Vigo.