The Copa del Rey quarter-final draw was revealed on Friday, and Real Madrid will face Leganes, while Barcelona will face their district rival, Espanyol.
Los Blancos now sit 16 points behind leaders FC Barcelona, after they drew 2-2 with Celta Vigo last weekend.
Pablo Fornals netted Villarreal's victor in the 87th minute, prompting loud boos by the home crowd which three days ago saw their team draw with second-division club Numancia 2-2 in the Copa del Rey.
Fornals struck with three minutes left to leave Zinedine Zidane's wasteful side fourth and a whopping 16 points behind runaway league leaders Barcelona, a deficit which will turn into 19 should Barca win at Real Sociedad on Sunday.
Villarreal moved to fifth place.
The game kicks off at 3.15pm meaning it is not available on UK TV, instead the Girona vs Las Palmas game was on at 12pm and Eibar v Atletico Madrid is on at 5.30pm and Deportivo La Coruna v Valencia at 7.45pm.
Ronaldo also had a chance just moments before halftime.
They were the far more active side, holding 56 percent of possession and having 18 shots compared to Villarreal's four, but they couldn't find the finishing touch despite several close calls-including Gareth Bale being ruled offside after finding the net off a corner and Cristiano Ronaldo hitting the outside of the post.
Former Madrid forward Denis Cheryshev came close with a shot for Villarreal after halftime, and Fornals didn't miss when he had his chance near the end.
Villarreal launched a lightning counter-attack led by Cheryshev, who slipped in Unal and, although his shot was saved by Keylor Navas, Fornals was on hand to brilliantly clip his shot over the stranded Madrid goalkeeper to spark jubilant scenes on the away bench.