Villarreal's Marcos Senna curled a free-kick around the wall and just wide of a full stretch Iker Casillas in the 82nd minute at the Madrigal and Real lost their heads.
Coach Jose Mourinho, Sergio Ramos and Mesut Ozil were all sent off in the following minutes and the visitors failed to add to Cristiano Ronaldo's wonderful 62nd-minute strike.
Real, seeking to prevent Barcelona's fourth consecutive title, climbed to 72 points with 10 matches left but second-placed Barca, who were 10 points adrift last week, were now just six points behind on 66.
Lionel Messi netted a hat-trick in a 5-3 home win for Barca over Granada on Tuesday.
"We still have to improve in many areas," Real's Brazilian defender Marcelo told Spanish television.
"Today we conceded at a set piece again but we are still ahead and we need to keep on working. We aren't nervous. Any team would want to be in our situation with a six-point lead."
Villarreal's experienced new boss Miguel Angel Lotina, in the post since Monday as their third coach of the campaign, had his side fired up and they caused Real plenty of problems.
Nilmar caught out the visiting defence on a number of occasions, and Casillas was forced into some smart saves.
Most of the action was down the other end, but Real failed to take their chances, until Ronaldo scored.
The Portuguese played a one-two with Mesut Ozil, the German returning the ball with a deft backheel, for his 33rd of the campaign.
Hamit Altintop gave away a free-kick just outside the area in a position similar to the one Santi Cazorla scored from to grab a last-minute equaliser at 1-1 for Malaga at the Bernabeu on Sunday, and former Spain international Senna scored.
Mourinho was immediately sent off for appearing to applaud the referee, following his assistant Rui Faria who had been dismissed earlier.
Ramos clattered into Nilmar to pick up a second yellow card a minute later, and Ozil also walked as he appeared to say something to the match official.
Mourinho did not attend the post-match news conference.
Earlier, basement club Real Zaragoza fired their slim hopes of avoiding relegation with a stirring comeback win at high-flying Valencia, and a double from Radamel Falcao gave Atletico Madrid a 2-1 victory at home to Athletic Bilbao.
Valencia stayed third in the table with 47 points, but city rivals Levante closed to within three points in fourth after they won 3-1 at Real Sociedad.
Zaragoza, who finished the match with nine men, humbled high-flying Valencia 2-1 despite falling behind to a Pablo Hernandez goal after only nine minutes.
They had defender Pablo Alvarez sent off in the 21st minute but Apono levelled with a penalty spot and bagged a winner in t
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.