Nacho Fernandez scored the only goal of the game midway through the second half to leave the defending champions two points adrift of rivals Atletico Madrid ahead of next weekend's concluding round of fixtures.
Diego Simeone's side were staring at defeat to Osasuna before Luis Suarez scored with only two minutes left to seal a 2-1 comeback win.
Zinedine Zidane, who has reportedly told his players he will leave Real at the end of the season, made two changes following their midweek win over Granada, with Alvaro Odriozola and Miguel Gutierrez coming into the Frenchman's starting XI.
Real saw plenty of the ball in the opening half but were unable to break the deadlock with the game goalless at the interval.
On the hour mark, Luka Modric called Unai Simon into action with a fine low drive before Nacho struck after 68 minutes.
The home side failed to clear their lines from a Real corner with the ball falling to Casemiro.
His cross went through the legs of Karim Benzema and hit Nacho as the defender claimed his first goal of the season and his first since February last year.
Benzema appeared to be in an offside position but, despite a Video Assistant Referee check, the goal stood.
Athletic Bilbao then ended the match with 10 men after Raul Garcia was dismissed in the closing stages.
Real host Villarreal next Sunday, while Atletico travel to Real Valladolid.