In the 17th minute Luis fed Denis with a dainty flick and the midfielder slotted home to open the scoring for the second time in five days.
The Uruguayan then netted himself but was caught fractionally offside as Barcelona looked for a second.
Eventually it came early in the second half as a lightning break downfield led to Inigo Martinez tripping Neymar in the penalty area.
Messi dispatched the penalty with pinpoint accuracy, firing it into the bottom right corner, with goalkeeper Geronimo Rulli going the right way but unable to keep it out.
La Real pulled one back when Juanmi ran in and flicked the ball over Jasper Cillessen’s head, but within a minute Luis Suarez struck at the other end after Messi slipped him in.
Willian Jose pulled another goal back for Real Sociedad with Barcelona’s defence sleeping, with a bullet header that flew into the bottom left corner.
Barcelona reacted with two more goals, one substitute feeding another when Aleix Vidal played in Arda Turan to score, before a brilliant pass from Messi saw Denis played in to jink around the goalkeeper and roll home for his second of the night.