The Argentina winger, who also scored a hat-trick in his last league match against Valencia, opened the scoring with a header after five minutes and added two more after the break to send his side 3-0 ahead.
That should have made the game safe for Barca, but Zaragoza rallied with a brace from substitute Adrian Colunga to set up a nervy ending.
Messi, however, quickly stamped out the threat as he embarked on another mazy run to earn a 90th-minute penalty which Zlatan Ibrahimovic, who until then had been profligate, slammed home for his first league goal since February 14.
"It was a game of men, very demanding. The pitch was very slow and Zaragoza are in outstanding form, but we have gathered all our effort," said Barca coach Pep Guardiola.
"Credit to Zaragoza. It's a very physical team, dynamic and with good players. I did not expect a pitch with grass so high in such bad shape, I'd like to think it's because the machines are broken."