The draw for the Copa del Rey round of 16 was conducted on Friday.
There were no restrictions involving the top-flight teams in the draw, except that the lower-division clubs would get to play at home.
Real Madrid will play second-division club Zaragoza, while Barcelona takes on Leganes.
Defending champions Valencia have been paired with third-division club Cultural Leonesa, who eliminated Atletico Madrid on Thursday.
The round of 16 will still be played in single-elimination games for the first time this year.
However, the semi-finals will be decided with a home-and-away series.
The only other matchup between first-division clubs will be Real Sociedad versus Osasuna.
Sevilla will take on Mirandes, Athletic Bilbao play Tenerife and Villarreal clash with Rayo Vallecano.