Mario Mandzukic handed the visitors the lead early on and Carlos Vela equalised within five minutes to make things level at the break, while Guilherme Siqueira was sent off early in the second half before Agirretxe headed home the winner after 82 minutes.
The three points see Sociedad, who have been strongly linked with David Moyes for their vacant head coach position, move out of the bottom three and into 15th, while the reigning champions remain fourth – level on points but with a better goal difference than Sevilla.
Sevilla also dropped points as Victor Casadesus’ second-half equaliser allowed struggling Levante to earn a 1-1 draw.
Vitolo’s header gave the hosts the lead after half an hour but Levante never let their heads drop and got a deserved equaliser in the 80th minute through Casadesus, although Sevilla passed up a litany of late chances to grab a winner.
The Yellow Submarine had looked set to put successive defeats to Sevilla, Valencia and FC Zurich behind them with a three-point haul at the Power8 Stadium thanks to Mario Gaspar’s first-half goal.
However, with the match having already entered additional time at the end of the game, Espanyol stunned their visitors by drawing level through Colotto’s close-range finish.