The first half began in frantic fashion with Barcelona scoring after just three minutes as summer signing Jori Alba got his first goal for the club, finishing well after beating the offside trap.
It seemed that the game was over after 17 minutes when Barcelona scored their third. Cesc Fabregas produced a clever back-heel to free Messi, who fired the ball in from outside the penalty area.
The Argentine almost got his second of the game soon after. It was David Villa with the pass this time, but Aranzubia was able to save the shot.
From the resulting corner Deportivo finally mounted a telling counter-attack. Riki raced clear and was adjudged to have been brought down inside the box by Javier Mascherano. Pizzi scored the penalty to get the home team back in the match.
The goal seemed to instill belief back into Deportivo and they pushed forward looking for a second goal.
On 37 minutes they found it. Victor Valdes may be disappointed with his efforts to save Alex Bergantinos's shot, but the ball squirmed in nonetheless.
There was still time for Barcelona to get one more before the break. It was Fabregas again with the assist, finding Messi with a good pass and the Argentine did the rest.
Deportivo were right back in the game straight after half-time.
One minute into the second half, they were awarded a free-kick on the edge of the box. Pizzi stepped up and hit the ball into the top corner to get his second of the game.
More drama ensued five minutes later when Mascherano was sent off for a second bookable offence.
That did not stop the away side though, who were awarded a free-kick of their own just outside the box. Messi stepped up aiming for his hat-trick. He was able to beat the wall and Aranzubia but his effort struck the post.
The game continued in end-to-end fashion before Barcelona brought on Xavi in an attempt to regain control.
It seemed to have worked when Messi completed his hat-trick fifteen minutes from the end. After turning on the halfway line, Messi ran towards the box, committing two defenders, before scoring into the bottom corner.
Just one minute later Deportivo made it 5-4 when a counter-attack found Riki at the back post. The striker could not control the ball but Alba inadvertently looped the ball over Valdes and into his own net.
The home team continued to push for an equaliser but Barcelona were able to hang on for all three points.