Real Madrid was previously the only side to claim a result against the Catalans with a 2-2 tie last October, but Madrid's exploits were bettered by a heroic showing from the Basque outfit, which fought back from two goals down to clinch victory.
Lionel Messi scored for a record 10th game in a row when he opened the scoring after seven minutes, before Pedro doubled the advantage with 25 minutes on the clock to seemingly put Barca 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 home side, as Barca could now see its 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 lineup for Barcelona, 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 in just the seventh minute. Messi had already drilled a one-on-one wide, and 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 which 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.
The second goal 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 halftime after lifting the ball over Bravo, but the ball 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 pass 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 equalized 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 was already rattled by the renewed endeavor of Sociedad, and 11 minutes into the second half, the 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 defense, and Chori took fortuitous advantage, sending in a shot that Mascherano deflected in despite a touch from Valdes.
The match seemed destined 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 in the team's history.
Follow @GoalUSA on Twitter.