Enrique de Lucas scored in extra time as Celta Vigo came from behind in dramatic fashion to oust second-tier club Almeria 3-0 from the Copa del Rey on Thursday after Roberto Lago had netted in the dying moments to extend the match.
Celta will face 2011 cup winner Real Madrid in the round-of-16.
"My players gave an enormous effort," said Celta coach Paco Herrera. "Little by little we found our way into the game, and when we started to string together short passes the chances arrived.
"We are happy to have qualified for the next round and for the rival that awaits us. Madrid is the present we wanted to give our fans."
Almeria entered the match at Balaidos stadium with a 2-0 goal advantage and looked set to move on despite Celta's Park Chu-young halving the margin with a header in the 55th.
But as the final seconds of stoppage time ticked down, Lago was left unmarked to sweep in a corner flicked on to the far post to level the aggregate score at 2-2.
De Lucas took Andres Tunez's through pass and rounded the goalkeeper before firing home from an angle 19 minutes into extra time.
Real Zaragoza and Mallorca also classified for the fifth round on Thursday.
Ten-man Zaragoza eliminated Granada on the away goals rule after losing 2-1 to go through 2-2 on aggregate.
Following Odion Ighalo's opener for Granada in the 27th, midfielder Jose Maria Martin struck an exquisite volley from a pass by Helder Postiga in the 55th to give Zaragoza its away goal that proved key to the two-legged series.
Postiga was sent off for a second booking after simulating a foul four minutes later, and Granada's Diego Mainz scored a header in the 66th.
Zaragoza goalkeeper Leo Franco made back-to-back saves inside the six-yard box in injury time to secure his team's meeting with Levante in the next round.
"We began the second half well and had the series in our hands, but at the end we had to make good on the goal we scored in the first leg," said Zaragoza coach Manolo Jimenez.
Mallorca ousted Deportivo La Coruna by holding on for a 0-0 home draw, going through thanks to its away goal from the 1-1 draw in their first meeting.
Joaquin Caparros' Mallorca will meet Sevilla next.
The second leg of the series between Athletic Bilbao and third-tier club Eibar was postponed and will be played on Dec. 12 as Bilbao's Europa League match with Hapoel Kiryat Shmona was played on Wednesday. The two Basque teams drew 0-0 in the first leg.