Pierre-Emerick Aubameyang scored the game's only goal after just 11 minutes before Barcelona were forced to withstand heavy pressure from their opponents, particularly in the second half. Coach Xavi Hernandez was also left sweating on the fitness of his defence, with all four members of his starting backline requiring treatment during the game and Ronald Araujo, Dani Alves and Gerard Pique all taken off.
- ESPN+ viewers' guide: LaLiga, Bundesliga, MLS, FA Cup, more
- Don't have ESPN? Get instant access
The win snapped a run of back-to-back losses for Barcelona that saw them eliminated from the Europa League and effectively ended their chances of catching Real Madrid at the top of LaLiga.
In the quest to finish runners-up, Barca are level on points with third-placed Sevilla and two points clear of fourth-placed Atletico Madrid, while having a game in hand on both. The victory also gave Barcelona some breathing room as they look to secure a top-four spot and place in next season's Champions League. Fifth-placed Real Betis are six points back, having also played a game more. Sociedad stay sixth, two points further back.
"It is the game that I have suffered the most since I arrived in November," Xavi told Movistar Plus.
"Real Sociedad dominated the game, they are a great team, they put us on the ropes and deserved more, perhaps a draw.
"That is why it has been a vital win, a precious victory. It was a well fought and very important result that leaves us in second place, close to our objective of going to the Champions League next season."
Aubameyang had given Barca the perfect start when heading in from close range following Ferran Torres' lobbed ball across the six-yard box. The goal was Aubameyang's ninth in LaLiga for Barcelona since joining from Arsenal in January.
But the visitors were made to work for the three points as Sociedad had a series of clear-cut chances either side of half-time to draw them level on the scoresheet.
Alexander Isak and Alexander Sorloth both failed to make clean contact with the goal gaping and just the keeper to beat, before Marc-Andre ter Stegen pulled off a fine save with his legs to deny Sorloth from similarly close range.
While he awaits more news on the fitness of his defenders, Xavi said the tactics he has implemented since being appointed last November explained the rash of injuries.
"Changing model of play, wanting them to press for 90 minutes," he told reporters. "A long time since Barca did that: press high, press after losing ball. It's draining physically, especially for the defenders who have to cover a lot of ground. It's because of that change. Only been five months. Before there was a medium-low block. Also the calendar is very demanding. But huge effort from players who want to be in Champions League next season."
Information from Reuters was used in this report.