The Basque outfit, who defeated Barcelona 3-2 in the corresponding fixture last term, went ahead in the 32nd minute when Gorka Elustondo's header found the net via the shoulder of visiting defender Alex Song.
Lionel Messi equalised four minutes later with a typically clinical finish, but further home goals in the first 14 minutes of the second half - scored by Antoine Griezmann and David Zurutuza - ensured the Primera Division champions left San Sebastian empty-handed for the third time in four seasons.
Barcelona headed into the game buoyed by their midweek 2-0 Champions League win at Manchester City, but having fallen three points behind arch rivals Real Madrid at the summit following the capital club's 3-0 victory over Elche earlier in the day.
Pedro Rodriguez passed up their only notable chance of the first half-hour, firing wide after a slick one-two with Andres Iniesta in the 19th minute, while Carlos Vela was unable to capitalise when presented with the best of the early opportunities for the hosts.
The opening goal arrived in the 32nd minute, though, when the champions were caught out by a short corner. Sergio Canales produced a fine first-time cross towards Elustondo, who nodded home via a deflection off Song.
The lead lasted only four minutes, though, before Messi equalised.
The Argentina forward had been on the periphery of proceedings until that point, but popped up to coolly despatch a low shot into the bottom right corner following neat interplay with Sergio Busquets. Tellingly it was Barcelona's only shot on target in the first half.
Sociedad should have gone in at the break ahead, but Vela blazed over the bar after being presented with an opening by some sloppy defending from Gerard Pique in the 40th minute.
Jagoba Arrasate's side did restore their lead early in the second half, however.
The visitors were given a warning on 52 minutes when Mikel Gonzalez headed a Canales free-kick narrowly over when well placed, and two minutes later Sociedad were 2-1 up.
A long punt downfield by goalkeeper Claudio Bravo was met by the head of Barcelona defender Marc Bartra, but he only managed to flick the ball on to Vela, whose early square ball for Griezmann caught Barcelona cold. The Frenchman still had work to do but, on the slide, he made the perfect connection to lash high past Victor Valdes.
And, before Gerardo Martino's side could regroup, they found themselves two goals down.
Griezmann was again involved, supplying the perfect cross in for Zurutuza, who had breezed into the Barcelona box unnoticed and got his left foot to the ball to poke home ahead of the out-rushing Valdes.
Sociedad could and should have extended their lead in the 81st minute when substitute Xabi Prieto pounced on more hesitant play by Pique and unselfishly teed up Vela, but his low shot rebounded off the post.