Real were again without the injured Cristiano Ronaldo, who also missed the goalless first leg of their Champions League semi-final at Manchester City.
Striker Karim Benzema was also absent but Bale filled the void with his 19th goal of the season.
Real play the return leg against City on Wednesday night.
Relive how Real Madrid kept their title hopes alive.
Bale had missed a number of chances as Zinedine Zidane's side chased a 10th successive league win to keep the pressure on title rivals Atletico Madrid, who later beat Rayo Vallecano 1-0, and Barcelona, who went back to the top after beating Real Betis 2-0.
But the Wales international, 26, who scored twice as Real beat Rayo Vallecano a week earlier, enhanced Real's chances of a first title success since 2012 when he powerfully headed home a cross from Lucas Vazquez.
Real Madrid coach Zinedine Zidane: "I am happy for him (Bale) because he has had problems this season with injury. But when he is fit you notice.
"We could have scored earlier in the first half, but we had to work until the end against a difficult side.
"I am happy with the performance and to get three points once again."
Gareth Bale headed in a late goal as Real Madrid won 1-0 at Real Sociedad to briefly go top of La Liga.