After title rivals Real Madrid lost earlier in the day, Barca could have moved to the brink of La Liga glory had they picked up all three points.

The result gives Madrid a more realistic chance of overhauling Barca at the summit with just four games remaining, although with eight points to make up their hopes remain slim.

All appeared to be going to plan for Barca when Thiago Alcantara fired the visitors into a 29th-minute lead.

But Diego Ifran forced an equaliser for the hosts on 71 minutes, before Javier Mascherano's foul on Antoine Griezmann paved the way for Sociedad to grab an unlikely win eight minutes from the end.

Xabi Prieto stepped up to take the spot kick, which was hugely unconvincing but somehow found its way past Barca keeper Jose Manuel Pinto.

Earlier, Jose Mourinho's Madrid lost 3-2 to Real Zaragoza just three days after seeing their Champions League hopes take a massive hit with a 2-0 semi-final first leg defeat to Barca at home.

Angel Lafita was Madrid's tormentor-in-chief, scoring two of Zaragoza's goals and winning the penalty that led to Gabi scoring the third.

Madrid had hit back from 2-0 and 3-1 down with goals from Sergio Ramos and Karim Benzema but they could not find a third, and they also finished the match with 10 men following Ricardo Carvalho's late sending off.

In the day's other game, Sergio Aguero's late strike secured Atletico Madrid a 1-0 win over Deportivo La Coruna that lifts the capital club into the Europa League places.

The game looked to drifting towards a drab stalemate until the Argentina international pounced in the 80th minute, taking Juanfran's touch to net his 17th goal of the Primera League season.