Alex Berenguer netted a late winner in the 89th minute to record a famous win.
Athletic had dominated the match at San Mames without being able to make a breakthrough until that point.
Madrid’s best chance fell to Casemiro, whose low second-half shot was saved by keeper Julen Agirrezabala.
Carlo Ancelotti’s men went into the game without injured top scorer Karim Benzema and without a recognised left-back, with Ferland Mendy, Marcelo and Miguel Gutierrez all absent.
Ancelotti opted for David Alaba on the left, and selected a front three of Vinicius Junior, Rodrygo Goes and Marco Asensio.
Los Blancos are still top of LaLiga and face Paris Saint-Germain in the knockout stages of the Champions League.