Unconvincing Madrid stunned as Alavés strike at the death
The European champions went into the game having failed to win in three games in all competitions, though their goal-shy attack was boosted by the return of Gareth Bale to the starting lineup.
Keen to end their poor run, the visitors started well, with Karim Benzema and Dani Ceballos both calling Fernando Pacheco in the home goal into action.
However, despite their promising start there continued to be signs of the defensive lapses that have marred their recent performances, particularly when Jony was allowed to chase a long ball in behind all alone, only for his poor first touch to spare Madrid's blushes.
Ibai Gómez perhaps should have done more to get something on an inviting Rubén Duarte cross minutes later as the two sides exchanges spells of pressure in an increasibgly physical encounter.
Neither was able to find a brekathrough, though, and the scoreline remained goalless at the break.
Mariano Diaz was summoned from the bench by Julen Lopetegui at the interval, replacing the misfiring Benzema, but his introduction did little to add to Los Blancos' cutting edge in the final third.
Indeed, the second half started as the first ended, with Toni Kroos having to be alert to deny Gómez a clear strike on goal and Casemiro forcing a low save from Pacheco with a long-range strike.
Duarte responded in kind at the other end, before Jony looked to have wasted the game's best chance as he dragged a left-footed effort wide of the far post after galloping away down the left flank.
However, there was to be a huge twist in the tale late on as the hosts struck with the last kick of the game to seal an unlikely win.
Jony earned his side a corner down the left deep into stoppage time, before whipping in an inviting ball to the far post. Rubén Soriano met it and whilst he was denied but the outsretched right hand of Courtois, there was nothing the Belgian could do to prevent Manu García from stealing in ahead of Sergio Ramos to head home the loose ball from a couple of yards out.
The win sees Alavés move into third, level on points with Real Madrid and Barcelona, with only goal difference preventing them from topping the table.