Leganes from the Madrid suburbs were pitted against 19-time Cup winners Real in Friday’s draw having progressed to the last eight on away goals in their two-legged last 16 tie against Villarreal on Thursday.
Zinedine Zidane’s Real laboured to a 2-2 draw with Numancia on Wednesday to progress to the quarter-finals 5-2 on aggregate.
Barcelona, who were watched by their new recruit from Liverpool Philippe Coutinho, cruised through 5-0 for a 6-1 aggregate beating of Celta Vigo, will face Espanyol.
Barca are seeking a 30th Spanish Cup success.
Atletico Madrid were drawn against Sevilla with Valencia up against Alaves.
The first legs are scheduled for January 16-18 with the return legs on January 23-25.
Copa del Rey quarter-finals
Leganes v Real Madrid
Espanyol v Barcelona
Atlético Madrid v Sevilla
Valencia v Alaves