Real had earlier deployed close to their strongest team in a 1-0 victory at city rivals Getafe, defender Sergio Ramos nodding in the only goal on a bitterly cold and blustery night at the Coliseum stadium that lifted them to 55 points from 21 matches.
In the late kick-off at an equally chilly Nou Camp, more than 50,000 fans turned out to witness Barca's 10th victory in 11 home league games this season that kept them within seven points of their arch rivals.
With Wednesday's King's Cup semi-final second leg against Valencia looming, coach Pep Guardiola had opted to start with regulars including World Cup-winners Xavi, Sergio Busquets and Gerard Pique on the bench.
B-team players Jonathan dos Santos, Cristian Tello and Isaac Cuenca were included in the starting XI, with Cesc Fabregas taking on the playmaker role in central midfield.
Pacy 20-year-old Tello opened the scoring in the ninth minute when he dashed in from the left wing on to a Messi through ball and finished clinically past goalkeeper Claudio Bravo, his debut goal for the first team.
World Player of the Year Messi, who had earlier been denied by several excellent saves from the Sociedad goalkeeper, made it 2-0 in the 72nd minute when he hooked in a Daniel Alves cross before Carlos Vela pulled one back for the visitors two minutes later.
Messi's strike put him on 23 league goals for the season, one behind Real forward and top scorer Cristiano Ronaldo, and Sociedad coach Philippe Montanier said the Argentine had been the difference between the two sides.
"Messi is a magician and anything can happen when he is on the pitch," Montanier, whose team are 13th on 24 points, told a news conference.
"I know that Barca have been playing a lot of matches and they had to make quite a few changes but they played the way they always do," the Frenchman added.
The Spanish and European champions' night was spoiled by a nasty-looking injury to Busquets.
The Spain midfielder had come off the bench only a few minutes earlier before he sustained a deep gash below his right knee in a challenge with Sociedad defender Carlos Martinez.
Initial local media reports said it was nothing serious and he may be available for Wednesday's cup game against Valencia.
In the earlier kick-off in Madrid, Ramos rose above the home defence to head a Mesut Ozil corner high into the net in the 18th minute as Real brushed aside the team who inflicted Barca's only defeat of the season in November.
They comfortably held a toothless Getafe at bay and it was a sixth straight league win for Jose Mourinho's side since they lost 3-1 at home to Barca in December.
"In this league nobody is going to gift you anything and each match will be even more difficult as all the teams have objectives to reach," Ramos said in a television interview.
"The season is very long but the gap to the second-placed team is a reality and 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.