The Argentine scored twice and set up a third for Paco Alcacer as Barcelona saw off their Basque opponents, who pressed them until the end of a nervy encounter.
After Real Madrid’s last-gasp victory over Sporting Gijon earlier in the day the Catalans’ win takes them three points behind Los Blancos, having played one match more, ahead of next Sunday’s Clasico.
Messi put Barcelona ahead with a low drive and doubled the lead with a tap-in, but Sociedad hit back when Inigo Martinez’s shot bounced off Samuel Umtiti into the Barcelona net.
Alcacer extended the Catalans’ advantage before Xabi Prieto reduced the deficit to 3-2 just before halftime, while the second half stayed goalless despite pressure from the visitors. (Editing by Toby Davis)