La Liga side Celta left it until two minutes into added time to level the tie at 2-2 before Enrique De Lucas scored in the 109th minute to send them through.
Zaragoza won 1-0 at home in the first leg and a 2-1 win for Granada in the return match was not enough for the Andalucians, with Levante waiting in the next round.
Real Mallorca went through at the expense of Deportivo La Coruna, also on away goals, after the two rivals from La Liga drew the second leg 0-0 in Palma and 1-1 on aggregate.
Mallorca next meet 2010 winners Sevilla.
The format of the Copa means it is extremely difficult for teams from lower divisions to get the better of top-flight opponents as they typically have to play away in the second legs.
The only non-La Liga sides left in the competition are second division Las Palmas and Cordoba.
Last 16 line-up:
Celta Vigo v Real Madrid
Osasuna v Valencia
Cordoba v Barcelona
Atletico Madrid v Getafe
Las Palmas v Real Betis
Levante v Real Zaragoza
Mallorca v Sevilla
The first leg at Eibar finished 0-0 but the second leg was postponed due to a clash with Bilbao's Europa League match at Israeli side Hapoel Ironi Kiryat Shmona.