Alex Berenguer struck a brilliant winner in the 89th minute to send Marcelino's men into the last four, where Valencia, Real Betis and Rayo Vallecano await.
Madrid had beaten Athletic 2-0 in last month's Supercopa final but could not find a breakthrough at San Mames in the absence of Karim Benzema.
It means Athletic, which eliminated Barcelona in the previous round, could now reach its third consecutive Copa final, having lost the previous two to Barca and Real Sociedad.
Clear-cut chances were scarce in the first half, but it was Athletic who carried the threat, with 10 shots to Madrid's three despite having only 41.3 per cent of the possession.
Indeed, Carlo Ancelotti's men ended the half with just 0.1 expected goals, their lowest tally for the first 45 minutes of any match since a 1-0 away win over Real Valladolid in January 2020.
Inigo Martinez saw a header well saved by Thibaut Courtois early in the second half, before Raul Garcia glanced an effort wide via a deflection and Berenguer, on for the injured Nico Williams, fired over.
Madrid began to assume more control as the 90 minutes wore on and Casemiro spurned a great chance, firing straight at Julen Agirrezabala from Marco Asensio's clever backheel.
Yet just as extra time beckoned, Berenguer produced a moment of magic, turning cleverly onto his left foot inside the Madrid box before bending a superb strike to the right of Courtois.