Barcelona were dumped out of the Copa del Rey on Thursday as Ferran Torres' first goal for the club failed to prevent a dramatic 3-2 defeat after extra-time by Athletic Bilbao.
Barca crash out of cup after extra-time defeat by Athletic Bilbao
Eden Hazard scored his first Real Madrid goal in eight months.
Disappointment for Barca was compounded by the sight of a visibly upset Ansu Fati going off injured in the second half of normal time at San Mames.
Fati only returned earlier this month after two months out with a hamstring problem, having also come back in September following 10 months out with a knee injury.
Another spell on the sidelines for Fati would be a huge blow to Barca's hopes of making La Liga's top four. Pedri also asked to go off in extra-time.
Real Madrid needed an extra 30 minutes as well to defeat Elche 2-1, with Eden Hazard grabbing the winner after Marcelo's red card forced La Liga's leaders to come from behind with 10 men.
Isco scored the equaliser after Gonzalu Verdu put Elche in front.
"It may be that Hazard and Isco deserve to play more," said Carlo Ancelotti. "I know I can count on them."
Barca were hoping to join Real Madrid in the last eight but instead it is Athletic who advance, joining Madrid, Real Sociedad, Mallorca, Rayo Vallecano, Cadiz, Valencia and Real Betis in Friday's draw for the last eight.
Madrid will be firm favourites, particularly after Sevilla crashed out at the hands of Real Betis, who are now perhaps the greatest threat to Ancelotti's side winning their first Copa del Rey since 2014, during Ancelotti's first tenure as coach.
Barca won the Copa del Rey last season and defending their title was probably their best chance of silverware this term.
They are out of sight in La Liga and were beaten by Madrid in last week’s Spanish Super Cup, with the Europa League now their only realistic remaining route to a trophy.
"They have beaten us on intensity," said Xavi Hernandez. "We have to change the dynamic because when it's heads or tails we always get tails. You have to work and be brave."
Only 102 seconds had passed when Iker Muniain sent San Mames apoplectic by collecting Nico Williams’ cross at the back post, before turning and bending into the far corner.
But Barcelona were level in the 20th minute, and from a similar angle, as Torres shifted right, inside Oscar De Marcos, and whipped a stunning shot into the net.
Inaki Williams hit the bar with a long-range effort late on but the real drama was still to come. Athletic thought they had won it in the 86th minute when Inigo Martinez prodded in at the back post ahead of the sliding Gerard Pique.
Barcelona, though, found a way back in the 93rd, as Dani Alves bicycle-kicked Jordi Alba's cross back into the area and Pedri's hit on the stretch was too powerful for Julen Agirrezabala's right hand.
Barca celebrated like it was the winner but there was extra-time to come and injuries. Fati went off and then Pedri asked to depart.
Then in the 103rd minute, a sliding Alba stopped Nico Williams' cross with his right arm and after consulting the replay, Jose Munuera pointed to the spot. Ter Stegen dived right, Muniain shot left.
Hazard had earlier scored his first Real Madrid goal in eight months as Madrid staged a dramatic comeback with 10 men to beat Elche.
The Belgian has been fit but still on the fringes of Ancelotti's team in recent months and even in this cup game, he started on the bench.
But the 31-year-old came on for extra-time and will hope his winner can now be the beginning of a resurgence in the second half of the season.