Real Madrid had previously been the only side to claim a positive result against the Catalans this season, with a 2-2 tie last October, but their exploits were bettered by a heroic showing from the Basque outfit, who fought back from two goals down to clinch victory.
Lionel Messi scored for a historic 10th game in a row when he opened the scoring after seven minutes, before Pedro doubled the visitors' advantage with 25 minutes on the clock to seemingly put them out of sight.
But Sociedad responded five minutes before the break through Chori Castro, and took full advantage of Gerard Pique's second-half red card to draw level through a Javier Mascherano own goal shortly after the hour mark.
It seemed destined to end in a draw, but substitute Imanol Agirretxe struck in injury time to clinch a famous victory for the hosts which means that Barca could now see their lead at the top of the table cut to eight points should Atletico Madrid win against Levante on Sunday.
Cesc Fabregas, Pedro and Pique returned to the starting line-up for the visitors, with Alex Song, Alexis Sanchez and Javier Mascherano making way after their exertions in the Copa Del Rey against Malaga midweek.
The Catalans were ahead as early as the seventh minute. Messi had already drilled a one-on-one wide, but made no mistake at the second time of asking, slotting home superbly from the edge of the box after Barca had pounced on a terrible clearance from Claudio Bravo.
Xabi Prieto came close to responding with a shot that hit the side netting, after a clever move from a free kick, but it was Barca who should have scored again after winning the ball inside the Sociedad box, with Pedro unlucky to see his splendid curling effort crack off the far post.
However, a second goal for the visitors was always on the cards, and when Dani Alves delivered into the six-yard box after being picked out wonderfully by Xavi, Pedro’s close-range finish was inevitable.
Messi could have made it 3-0 five minutes before half-time after lifting the ball over Bravo, but his lobbed effort rolled onto the post before being hacked clear by Mikel Gonzalez.
Instead, within moments, it was 2-1. Chori did well to control a Carlos Vela cross just inside the box and the Uruguayan picked his spot brilliantly, firing into the bottom corner.
The home fans were back in full voice and Chori could have equalised with an identical chance seconds after the restart, but this time Victor Valdes was up to the task and parried the shot away from danger.
Barca were already rattled by the renewed endeavour of Sociedad and, 11 minutes into the second half, their cause was further dented when Pique picked up his second yellow card for a clumsy trip on Vela.
With the Catalans on the ropes, Sociedad struck another decisive blow just after the hour mark. A cross into the area was not dealt with by the defence and Chori took advantage, albeit in fortuitous fashion, sending in a shot that Mascherano deflected into the back of the net despite Valdes' best attempts to keep out with his right hand.
The match seemed certain to end with both sides splitting the points, but with the clock moving into injury time, Agirretxe met a Carlos Martinez cross to seal a victory for Sociedad that will surely go down as one of the finest in their history.