The Argentine forward settled a cagey affair with his strikes in the final 20 minutes - the first an incredible free kick and the second a sweeping finish at the end of a quick counter.
Barca were below par until their main man stepped up, with Messi's double taking them 13 points clear of Atletico Madrid after playing a game more than their closest title challengers.
Messi uncharacteristically wasted a couple of half-decent opportunities in the goalless first half, firing the ball into Naldo in front of goal early on and then guiding a shot wide from a good position after a deflected pass landed nicely in his path.
The matchwinner nearly made a telling impact on the first half, though, as his free kick was glanced goalwards by an Espanyol player, forcing Diego Lopez into the only notable save of the opening period.
Ivan Rakitic also sent a bullet shot inches wide of the target from 25 yards and Luis Suarez fired the ball into the side-netting, but Espanyol otherwise did enough to keep their opponents at arm's length.
Despite having just 28% of the ball before half time, the visitors attempted to get forward as often as they could, without creating a chance of any sort.
Goalscoring chances also proved hard to come by in the second half, with Jordi Alba failing to find the target with his half-volley towards the back post in Barca's only opportunity before the hour mark.
Espanyol struggled to get out of their own half, but when they did manage to get forward it almost led to the opening goal of the match as Borja Iglesias picked out Oscar Melendo after making good ground down the right, but the striker's shot on the turn was saved by Marc-Andre ter Stegen.
Barca boss Ernesto Valverde brought on Malcom with a third of the match left to play, and the substitute forward nearly made an instant impact as he forced Lopez into a rare stop seconds after coming on.
Rakitic whistled another one wide and Philippe Coutinho blazed a shot over the crossbar as Barca continued to toil, but they eventually made the breakthrough thanks to their star man.
After being fouled by Victor Sanchez a yard outside the box, Messi's delicate free kick beat both Lopez and Sanchez on the line to get Valverde's men off the mark.
Ter Stegen played the ball to Rakitic, who sent Malcom through down the left and the substitute forward teed up Messi for a first-time finish that had too much on it for Lopez to keep out.
BARCELONA (4-3-3): Ter Stegen; Semedo (Roberto 59'), Pique, Lenglet, Alba; Rakitic, Busquets, Arthur (Malcom 59'); Messi, Suarez, Coutinho (Vidal 82')
ESPANYOL (5-4-1): Diego Lopez; Rosales, Lluis Lopez, Naldo, Hermoso, Pedrosa; Melendo (Garcia 65'), Sanchez (Semedo 78'), Roca, Granero; Iglesias (Wu Lei 64')