Barcelona s Gabonese midfielder Pierre-Emerick Aubameyang gestures during the Spanish League football match between Real Sociedad and FC Barcelona at the Anoeta stadium in San Sebastian on April 21, 2022. AFP
But Barca's run-in could be hampered after their defence was almost completely wiped out by injuries at Anoeta, with Dani Alves, Ronald Araujo and Gerard Pique all going off with problems while Jordi Alba appeared to play on in discomfort.
Barcelona relied on a combination of poor finishing from Real Sociedad and excellent saves from Marc-Andre ter Stegen to secure a big win in the chase for Champions League qualification.
"For long spells they dominated us, they had more of the ball than us - they are a great team, physically very strong. It's a huge victory for us," said Xavi.
Barcelona go back to second, six points clear of Real Betis in fifth, with a game in hand, and two ahead of Atletico Madrid in fourth. Atletico were held to a goalless draw by Granada on Wednesday.
Sevilla sit third after they held on for a 3-2 win away at Levante, Tecatito scoring twice in Valencia.
Real Sociedad might have had an outside chance of joining the race for the top four if they had beaten Barcelona but defeat surely leaves them looking to secure a spot in the Europa League. They are six points behind Atletico in fourth.
Aubameyang's goal was his 11th for Barca since he joined the club in January and this one was particularly important, with his team eager to overturn an unexpected dip in form.
Xavi challenged his players on Wednesday to escape the "negative dynamic" after back-to-back defeats by Eintracht Frankfurt in the Europa League and Cadiz at Camp Nou.
There was controversy off the pitch too, as Pique found himself in the middle of a media storm this week after leaked audio messages revealed unseemly conversations with the president of the Spanish football federation, Luis Rubiales.
Pique's early touches were whistled by the Real Sociedad crowd, who jeered again when the 35-year-old was substituted in the 82nd minute.
Alves had already gone off in the 66th and Araujo in the 55th, with Barca now crossing their fingers the problems are not serious.
"We're at the end of the season, we're suffering a lot, a lot of fatigue and problems, it's normal with the calendar we have," said Xavi.
The decisive moment, though, came in the 11th minute as Ousmane Dembele hit the post when left free in the area. The ball cannoned out and La Real looked safe to clear until Gavi robbed the ball back, chipped it to Ferran Torres, whose looping ball across allowed Aubameyang to nod in.
Real Sociedad might easily have grabbed an equaliser but kept running into the Marc-Andre ter Stegen, who enjoyed an inspired night in the Barcelona goal.
Alexander Isak went close while Alexander Sorloth missed La Real's best chances, firing wide at the back post from Nacho Monreal’s cross and then taking too long after being picked out in the area by Adnan Januzaj.
Sorloth had another sight of goal late on, but his finish from the angle was brilliantly stopped by Ter Stegen, this time his left foot allowing Barca to hold on for an important victory.
(For more sports news and updates, follow Ahram Online Sports on Twitter at @AO_Sports and on Facebook at AhramOnlineSports.)