After only dropping two points in the first half of the season, Barcelona suffered their first loss on Saturday as they went down 3-2 at Real Sociedad.
Messi and Pedro put Barcelona in the driving seat but Castro pulled one back shortly before the break. In the second half, Piqué got himself sent off for a second bookable offence and Castro levelled the scores.
Well into injury time, Agirretxe got on the end of a cross and shot past Viktor Valdés to clinch victory.
Málaga failed to take advantage of this slip by the leaders, only managing to draw at home to Celta. Demichellis put the Blue and Whites in front in the first half but this was cancelled out by a strike from Augusto Fernndez midway through the second period.
Málaga are now fifth but under threat from Valencia and Levante, both of whom play on Sunday.