World Player of the Year Messi has not been at his best in recent games, failing to score in three outings, but quashed any debate over his form with a first-half treble at the Nou Camp that took his league tally this season to 13.
Barca youngster Isaac Cuenca and Dani Alves wrapped up the scoring in the second half to leave the champions second with 24 points from 10 games, one behind leaders Real.
Gonzalo Higuain gave Jose Mourinho's in-form Real Madrid a ninth-minute lead in San Sebastian but the team that netted 28 times in their previous seven matches were denied another hefty win by the battling Basques.
Barca coach Pep Guardiola left four World Cup winners on the bench, with a fifth (Xavi) resting in the stands, but they were not missed at the Nou Camp.
The hosts won a penalty for hand-ball in the 13th minute and Messi, who had a last-minute spot-kick saved last weekend, blasted the ball high into the net.
Adriano's cross-cum-shot was turned in by the Argentine in the 21st and Messi then volleyed the third from an Alves cross in the 30th.
Barca youth team forward Cuenca notched the fourth on his home debut in the 50th minute, rounding the keeper from Thiago Alcantara's defence-splitting pass, before Alves crashed in a fifth from distance at the end.
"It was madness when they said I was in crisis after three games," Messi told Spanish television.
"It doesn't bother me. I score when I can and when I don't the important thing is the team win."
Barca goalkeeper Victor Valdes kept a clean sheet for an eighth game in a row and edged towards a club record.
The Spanish international last conceded 787 minutes ago, in a 2-2 draw at Valencia last month, and is only 37 minutes short of the mark held by Miguel Reina, father of Liverpool keeper Pepe, from the 1972/73 season.
Higuain ran on to Fabio Coentrao's pass and dinked the ball over Claudio Bravo for the only goal at Socieded but Real Madrid were unable to turn their first-half dominance into a bigger lead.
Sociedad hit back after the break, forcing Iker Casillas into a couple of top-class saves.
Earlier, Villarreal dragged themselves out of the bottom three with a 2-0 victory at home to Rayo Vallecano, easing the pressure on coach Juan Carlos Garrido.
Bruno Soriano headed in at a free-kick after 20 minutes and captain Marcos Senna had a penalty saved just before the break.
Borja Valero settled nerves at the Madrigal with a solo effort in the 67th minute, earning Villarreal their second league win of the season.
The victory came at a cost, however, with Argentine striker Marco Ruben limping off to join first-choice forwards Nilmar and Giuseppe Rossi on the injury list.
Villarreal climbed to 13th with 10 points.
Elsewhere, fourth-placed Valencia (21 points) we
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.