The Argentina international struck three times at Camp Nou, passing through the 400-goal barrier in the process, while Gerard Pique and Pedro were also on target
Blaugrana academy product Sergio Garcia silenced Camp Nou by opening the scoring 13 minutes in but Messi levelled matters just before half-time.
The Argentina international put Barca ahead five minutes into the second half and, after Gerard Pique had headed home a third, the four-time Ballon d'Or winner completed his hat-trick with his second right-footed finish of the game.
There was even time for Pedro to add a fifth, as Barca warmed up for Wednesday's crunch Champions League clash with Paris Saint-Germain in fine style.
Barca started sluggishly, as Garcia flashed a cross in from the left, and only a last-ditch Jordi Alba intervention denied Lucas Vazquez an easy finish.
But clinical visiting play saw Espanyol seize the initiative as Felipe Caicedo robbed Sergio Busquets on the right flank, and fed Garcia, who breezed past Pique before executing a low finish past Claudio Bravo.
Garcia could only fire tamely at Bravo as Espanyol threatened to double their lead, but it only seemed to spur Barca on further as Messi struck the crossbar with a 30-yard free-kick, before Luis Suarez fired just wide.
And with home pressure building before the break, Messi bent an unstoppable effort into the bottom-left corner from 25 yards to restore parity on the stroke of half-time.
The visitors were somewhat lucky not to be reduced to 10 men in the 49th minute as Eric Bailly barged Neymar over with the Brazilian through on goal.
But it mattered little to Barca, who edged themselves ahead a minute later.
Messi's first touch from Suarez's pass was heavy, but he reacted quickly to poke the ball through Juan Fuentes' legs and then stroke right-footed past Casilla from the edge of the area.
And their third arrived shortly after, Pique atoning for his role in Garcia's opener as he headed Ivan Rakitic's corner into the net.
With the result already in little doubt, substitute Pedro latched on to Alba's exquisite cross-field pass before coolly slotting beyond Casilla in the 77th minute and Messi completed the rout four minute later.
The Argentine combined brilliantly with Pedro, playing a one-two into the area before steering into the net from 10 yards, securing his third hat-trick in four games and maintaining Barca's dominance over their near neighbours.