Barcelona survives, defeats Deportivo
It looked to be a one-sided affair when the league leaders raced into a three-goal lead through Jordi Alba, Cristian Tello and Messi after just 18 minutes.
However, Depor replied with a Luis Pizzi penalty and an Alex Bergantinos goal before Messi struck again to put Barca back in the driving seat.
Pizzi's second of the match then set the nerves jangling once more and the dismissal of Javier Mascherano gave the visitors further food for thought until Messi made it 5-3 with his treble.
The excitement did not stop there though, and an own goal from Alba brought Depor back within touching distance of their opponents with 11 minutes remaining.
However, despite their best attempts to grab a deserved equalizer, their luck ran out as Barca held on for the points.
Barca coach Tito Vilanova had left influential midfielder Xavi on the bench for the match, but his absence was hardly noticed as the Catalan side took the lead after just three minutes. Cesc Fabregas played a ball through to the feet of Alba, who planted a shot into the bottom left corner.
Depor had barely had time to register that goal when they conceded again five minutes later. Messi was the provider this time, setting up Tello for the striker to fire low into the net.
Barca were ruling the roost at the Riazor and Messi added his name to the scoresheet in the 19th minute with an accurate left-footed drive following Fabregas' back-heel.
Depor managed to respond this time and Barca goalkeeper Victor Valdes had to be at his best to tip over a shot from Bergantinos before Carlos Marchena headed the resulting corner over the bar.
Home goalkeeper Daniel Aranzubia was then called into action at the other end to deny Messi his second goal of the night.
Depor were beginning to show more purpose going forward and they were rewarded after 25 minutes when Mascherano was punished for a challenge in the area on Ivan Riki.
Pizzi was charged with taking the penalty, picking out the top right corner with his conversion.
Although Depor had only won once all season coming into this fixture, their confidence was growing and they further reduced the deficit after 37 minutes through Bergantinos' strike from 18 yards.
Barca's class shone through once more before the interval though, and particularly that of Messi, who netted the visitors' fourth of the night after again pairing up with Fabregas.
The first half had been a pulsating affair and there was nothing to suggest that would change after the break when Pizzi scored another for Depor within two minutes of the restart, curling a sublime free-kick into the top right corner.
Things took another turn for the worse for Vilanova's men two minutes later when Mascherano received a second yellow card - and his marching orders - for another foul on Riki.
It was Barca's turn to dig deep and Messi came close to completing his hat-trick after 51 minutes with a free-kick of his own which came back off the post.
The feat was achieved after 77 minutes with a lovely solo effort which saw the Argentina captain dribble his way through the Depor defense before striking an angled shot across the face of the goal and into the bottom right corner.
Typically, however, Depor struck back within the space of a minute, with a ball into the area which Alba lobbed over a helpless Valdes and into his own net.
That set up a tense final 10 minutes for Barca, but they held together when it mattered the most and Depor's late pressure failed to produced the fifth goal they so thoroughly deserved.
Information from The Associated Press was used in this report.