A header from Gerard Pique gave the Catalans the lead in the 19th minute to the delight of 20,000 fans who returned to the Camp Nou for the first time in 17 months, and Martin Braithwaite struck either side of halftime to extend their advantage.
Sociedad looked to be out of the game but substitute Julen Lobete pulled them back into contention in the 82nd minute and forward Mikel Oyarzabal scored a stunning free-kick moments later to set Barcelona nerves jangling.
Sergi Roberto struck in added time for the hosts, however, to make sure of the points in Barca's first match without all-time top scorer Messi, who joined Paris St Germain last week after 21 years with the Spanish club.
"We made things complicated for ourselves but we played a great game," said Pique.
"We controlled it for 80 minutes and although we were on the edge after their free-kick, we got the fourth goal. The new players adapted well and the fans were excited about the football we played."
Barca fans chanted Messi's name at kick-off while a section of supporters also booed in protest against president Joan Laporta, who had vowed to keep the Argentine at the club when he was elected in March.
Just under 30 000 tickets were made available for the game at the 99 000-capacity Camp Nou due to coronavirus restrictions but only 20 000 fans registered interest in attending, perhaps a sign of a lack of excitement for the new season without Messi.
But Barca dominated for most of the game with some flowing football, suggesting they could still have a promising future without their most iconic player.
The fans were lifted off their feet when Pique connected with a free-kick from debutant Memphis Depay to put Barca in front, a day after the club announced the defender had taken a pay cut to alleviate their financial problems so they could register the Dutchman and fellow new signing Eric Garcia.
"I grew up here, I've played almost all my life here and it was a gesture I had to make and I've been speaking to the other captains and they're going to do the same too," added Pique.
Braithwaite headed home a sumptuous cross from Frenkie de Jong at the end of the first half to put Barca further at ease and the Danish forward struck again in the second half, lashing home a loose ball after Jordi Alba's cross had been parried by visiting keeper Alex Remiro.
Barca then dropped their intensity and out of nowhere Sociedad stormed back into the game with two goals in three minutes to silence the cavernous stadium.
Pique made a gesture for the fans to liven up and help the team over the line and his side killed the game off on the counter-attack.
Antoine Griezmann led the charge through the middle before releasing Braithwaite, who crossed for Roberto to slide in at the back post and score their fourth.