The defender threw himself at Ilkay Gundogan's cross and headed the ball through goalkeeper Alex Remiro's legs.
It was initially flagged offside but the VAR ruled he was onside.
The win was scarcely deserved as Real Sociedad had the better chances - with Takefusa Kubo and Martin Zubimendi denied by Marc-Andre ter Stegen.
Barcelona move up to third but remain four points behind surprise La Liga leaders, their local neighbours Girona.
Girona's 4-2 win at Osasuna earlier in the day took the Catalan minnows back to the top of the La Liga table.