Barca beat Osasuna to set up Real showdown
Serbian forward Dejan Lekic put the home side ahead just before half-time at a foggy Reyno de Navarra stadium but any hopes of an unlikely comeback were snuffed out by Barca's Chile international Alexis Sanchez when he nodded the equaliser four minutes into the second half.
Teenage B-team midfielder Sergi Roberto grabbed the winner 18 minutes from time when he ran on to a pass from substitute Lionel Messi and crashed a superb angled shot past goalkeeper Asier Riesgo.
Barca, who lost 1-0 to Real in last year's final, travel to the Spanish capital for the first leg on Wednesday, with the return leg at the Nou Camp a week later.
The winners of the tie will meet city rivals Valencia or Levante in the semi-finals.
On the other side of the draw, Athletic Bilbao hammered third-tier Albacete 4-0 at San Mames to secure a last-eight tie against La Liga rivals Real Mallorca, who overturned a 2-0 first-leg deficit by thrashing Real Sociedad 6-1 on Tuesday.
The winners will meet either 2006 winners Espanyol or third-tier Mirandes, who disposed of Racing Santander on Tuesday, in the last four.