With second-placed Atletico Madrid travelling to Alaves later in the day, the champions took advantage of the chance to extend their lead.
A dull match was decided by Barcelona's number 10, who lofted home a free kick after 71 minutes and slotted in from substitute Malcom's cross towards the end.
Messi, the division's top scorer with 31 goals, suffered criticism in his native Argentina after withdrawing from a friendly against Morocco because of a groin problem, but was hailed by Barcelona fans after taking them one step closer to retaining the title.
Ernesto Valverde started Messi along with Luis Suarez, who had recovered from an ankle sprain.
But the duo and Philippe Coutinho were kept quiet in a tight first half, with Espanyol's five-man defence not giving the South American trio any space.
With Malcom's introduction in the final half hour, the game began to open up.
The Brazilian winger had a cross shot tipped wide by Diego Lopez, with Coutinho firing over the bar as Barcelona pushed for a winner.
The Catalans were short on inspiration until Messi produced a cheeky dinked free kick, which midfielder Victor Sanchez could not keep out on the goal-line, before tucking home his second on the break.
Barcelona were far below their fluid best but two moments of skill from talisman Messi secured three points from an otherwise forgettable game.
In another match the same day, Iago Aspas struck twice on his return from injury to earn Celta Vigo a crucial 3-2 win over Villarreal, leaving them one point and one position behind their 17th-placed opponents in the La Liga standings.