With the top two having already won on Saturday, Madrid knew anything other than victory at the Anoeta could spell the end of their title challenge, but they came away with the three points thanks to goals from Asier Illarramendi, Bale, Pepe and Alvaro Morata.
Former Sociedad player Illarramendi opened the scoring against the run of play on the stroke of half-time and then Bale - despite suffering a gash to the knee moments before - doubled the lead in the 66th minute, thanks largely to a huge error from home goalkeeper Claudio Bravo.
Bravo's attempt to kick the ball out of hand to a team-mate near the touchline ended up going straight to Bale 35 yards out, and the Wales international took a touch before slamming his shot into the unguarded net as Bravo scrambled to get across.
That goal was followed by two more late strikes from Pepe and Morata as Madrid claimed an impressive victory that keeps them within three points of leaders Atletico and within two of Barca.
Things were not looking so comfortable for Carlo Ancelotti's side in the first half though as the visitors - without the injured Cristiano Ronaldo and with Angel Di Maria only fit enough for a place on the bench - struggled to make much headway against Sociedad.
And it was the sixth-placed hosts who came closest to taking the lead with Diego Lopez producing a brilliant save from Carlos Vela - who was incorrectly adjudged to have been just offside - while Antoine Griezmannn glanced a header just over.
Vela then tested Lopez again before Madrid took the lead in the 45th minute through Illarramendi.
The 24-year-old midfielder, who Madrid bought against Sociedad's wishes last summer when they paid the reported £33.6million fee in his buy-out clause, showed good reactions to poke the ball home after Bravo had parried Karim Benzema's shot.
Madrid barely deserved that half-time lead, but they were full value for the points at full-time following an impressive second-half display.
Sergio Ramos and Benzema both saw efforts crash back off the crossbar either side of Bale's goal, while Xabi Alonso - another former Sociedad player - also went close with a free-kick that Bravo saved at full stretch.
Bale's goal came soon after he was left with cut knee following an accidental collision with two Sociedad defenders, and although he was able to continue after treatment, the hobbling Welshman did not look set to last much longer.
He was able to play on until nearly the end though, and during that time he put Madrid 2-0 up and saw Pepe volley home Ramos' cushioned header to make it 3-0 in the 85th minute.
Bale was taken off almost immediately after Pepe's goal, and the winger's replacement Morata wrapped up the scoring when he latched on to Di Maria's fine through-ball before slotting beyond Bravo.