Sociedad led 2-0 against the league leaders after 34 minutes of football, but Paulinho netted late in the first period before a second-half double from Luis Suarez and late Lionel Messi strike secured all the points for Ernesto Valverde's side.
The victory was Barcelona's first in the league at the Anoeta for over 10 years, and it has moved them nine points clear of second-placed Atletico Madrid. Champions Real Madrid, meanwhile, are now 19 points off the pace.
Read how it all unfolded in Sports Mole's minute-by-minute live commentary of the action below.
SOCIEDAD: Rulli; Odriozola, Llorente, Navas, Rodrigues; Zurutuza, Illarramendi, Prieto; Juanmi, Willian, Canales
BARCELONA: Ter Stegen; Roberto, Pique, Vermaelen, Alba; Busquets, Rakitic, Gomes, Paulinho; Messi, Suarez