Ten-man Barcelona lost its first match in the Spanish league on Saturday, squandering a two-goal lead in a 3-2 defeat at Real Sociedad and conceding an injury-time winner.
Lionel Messi scored for a 14th straight start to open for Barcelona in the seventh minute, and Pedro Rodriguez appeared to give the visitors full control with a goal in the 25th.
But Gonzalo "Chori" Castro pulled one back in the 41st and equalized in the 63rd after Barcelona's Gerard Pique was dismissed for a second yellow card.
Imanol Agirretxe went on in the 84th as Sociedad looked to press home its numerical advantage, and the striker charged forward to tap in Carlos Martinez's last-gasp cross for the winning goal a minute into stoppage time.
Barcelona had set a league record by winning 18 games and drawing only once by the competition's midway point.
"One day we were going to lose," Barcelona coach Tito Vilanova said. "Since it happened in the last minute I'm not worried. I don't have any reproach for my players. We hit the post twice and had several other chances in the first half. But not even with the 2-0 lead did I think it would be easy."
The Catalan club is still in command of the title race, 11 points ahead of Atletico Madrid before its game against Levante on Sunday. Defending champion Real Madrid is 18 points behind before Sunday's visit to Valencia.
Elsewhere, fifth-place Malaga was held to a 1-1 home draw by Celta Vigo. Sevilla drew 1-1 at Getafe in the league debut of coach Unai Emery, and Granada beat visiting Rayo Vallecano 2-0 to end its four-game winning streak.
For the second time in four days, Barcelona's defense failed to protect a lead. On Wednesday, it let 10-man Malaga rally to score with the 90 minutes complete and snatch a 2-2 draw in the first leg of their Copa del Rey quarterfinal.
Saturday's game was similar to last season's meeting in San Sebastian. In both games Barcelona scored twice to apparently have the game in hand before Sociedad roared back. Last year the same fixture ended 2-2.
"We could have finished off the game, but it is always tough to win here," Barcelona midfielder Xavi Hernandez said.
Sociedad, which has lost only one of its last 10 games - a 4-3 shootout at Madrid this month - pressed up the pitch from the start.
But Barcelona looked set to extend its 12-game league winning run with Messi and Pedro each scoring and hitting the goal frame.
Messi struck with his first career goal at Anoeta Stadium and his league-leading 29th goal of the season through 20 matches.
Moments after a rare miss by Messi one-on-one with the goalkeeper, Andres Iniesta poached Claudio Bravo's short goal kick, crossed the ball for Cesc Fabregas, who deftly let it roll through to Messi, and he quickly put the ball on his left foot before unleashing a precise strike just inside the upright.
It was then Pedro's turn to get it right the second time.
The forward was denied by the post in the 14th, but he made it 2-0 minutes later when he volleyed home Dani Alves' cross.
Sociedad came to life in the 41st when Castro was left unmarked on the left side to receive Carlos Vela's pass and rifle the ball past goalkeeper Victor Valdes.
Sociedad continued to apply pressure after halftime and soon found itself playing with an extra man when Pique was shown his second yellow card for cutting down Vela in the 56th.
"Going down to 10 men changed the game," Vilanova said. "I told Gerard that he would be sent off with the next foul."
The Basque side pushed short-handed Barcelona into its area and the effort paid off when Castro's strike took a deflection off substitute Javier Mascherano to catch Valdes out of position.
Barcelona didn't seriously threaten again, and the slow-footed Mascherano let Agirretxe slip behind him to reach Martinez's cross and end Barcelona's 15-game unbeaten streak in all competitions.
Ninth-place Sociedad stayed undefeated in six consecutive home games.
"There is no recipe for beating Barcelona," Sociedad coach Philippe Montanier said. "We won because we have a compact team that works hard, and we had a little bit of luck."
The defeat was Barcelona's first in league play since it lost to Madrid on April 21 of last season.
On Sunday, Osasuna hosts Deportivo La Coruna, and Valladolid plays Real Zaragoza. Athletic Bilbao visits Real Betis on Monday.
Espanyol beat Mallorca 3-2 on Friday.