Gerard Pique was sent off late in the first half for a second yellow card, and Barca went in 1-0 up at the break thanks to a Dimitris Nikolaou own goal in the 18th minute.
Messi settled any nerves that the visitors may launch a comeback with a neat free-kick just after the hour before setting up Lucas Digne for his first Champions League goal for Barcelona moments later.
Nikolaou headed a late consolation for the visitors, but the Catalans remain top of their group having won three from three in the 2017-18 tournament so far.
Both clubs provided their starting lineups ahead of kick-off:
Barca dominated from the off and could have been ahead in the fifth minute had Luis Suarez not surprisingly missed the target with a stretching effort at the far post after Samuel Umtiti's headed flick-on from a corner.
It only seemed a matter of time before the hosts went ahead as Olympiakos were inviting pressure, and it was eventually one of the Greek side's defenders who turned into his own net.
After holding out for the first 17 minutes, centre-back Nikolaou deflected home an own goal from Gerard Deulofeu's cross from the right.
The sparkling Deulofeu then forced a decent save from Silvio Proto in the 20th minute before Paulinho hit the bar moments later, and the Olympiakos goalkeeper then did excellently to keep out both Suarez and Messi before the break.
Pique did get the ball over the line three minutes from half-time. But instead of awarding a Barca goal, the referee correctly adjudged the Spanish centre-back had handled the ball into the goal and duly issued him a second yellow card.
Barca should have been home and dry by the break but were instead leading by just one goal and down to 10 men, and manager Ernesto Valverde then opted to replace Deulofeu with Javier Mascherano for the second half.
Just after the hour, Messi stepped up to ensure the three points as he curled home a fine free-kick, although Proto could arguably have done better to keep it out given he got a hand to it, per Spanish football writer Simon Harrison:
Per Opta, it was yet another milestone for the five-time Ballon d'Or winner:
In the 64th minute, the superlative Argentinian then created space on the right of the box and threaded a ball into Digne's path for the Frenchman to sweep home well with his left foot.
Barca looked to be heading for a clean sheet despite Pique's dismissal. But with seconds remaining of normal time, Nikolaou rose brilliantly at a corner and looped a header past the outstretched hand of Marc-Andre ter Stegen.