A stunning late free-kick at the end of an otherwise quiet outing from the Argentina star made him the top league goalscorer for one club in any of Europe's top five divisions, surpassing Gerd Muller with his 366th LaLiga goal.
The Catalan giants had returned winless from their last seven trips to Sociedad in the top flight and were primed for further disappointment after falling behind to Willian Jose's 11th-minute header.
Juanmi doubled the hosts' lead with a heavily deflected finish after a superb assist from Sergio Canales, but that only served to stir Barca into life and Paulinho reduced the deficit before half-time.
Within five minutes of the restart the scores were level as Luis Suarez finished brilliantly for his 12th league goal of the season.
Suarez then grabbed a second 19 minutes from time after goalkeeper Geronimo Rulli's poor clearance proved costly for Eusebio Sacristan's men, with Messi putting the icing on the cake.