Karim Benzema put Madrid ahead with a scorching strike from outside the area but Valencia replied with Soler's penalties and a bizarre own goal from Raphael Varane, inflicting a second defeat on Madrid this season.
The win took second-placed Real to 62 points after 29 games, two behind champions Barca.
Garay, who was set to miss the rest of the season with a knee injury, became the first player in La Liga to confirm a positive test earlier on Sunday.
Atalanta's European adventure continued in emphatic fashion as Slovenian Ilicic netted twice in each half to guide his side comfortably into the quarter-finals.
Gian Piero Gasperini's Serie A side raced into a two-goal lead by halftime with goals from Hans Hateboer and Josip Ilicic, while Valencia were denied by the post.
Barca are still top of the standings on 43 points after 21 games.
Real will meet the winners of Thursday's second semifinal between Barcelona and Atletico Madrid in Sunday's showpiece at the King Abdullah Sport City Stadium in Jeddah.
Valencia, who missed a glut of chances, had taken the lead through Carlos Soler but goals from Mateo Kovacic and Christian Pulisic flipped the match on its head.
If the recent seasons of La Liga have taught us anything, it's that Valencia is not to be trifled with.
Cillessen has been capped 50 times by the Netherlands and is their first-choice keeper.