Barca match consecutive win record
Promoted Hercules stunned the champions with a 2-0 win at the Nou Camp back in September, the only defeat Barca have suffered in the league this season, and they made life tough for the visitors until Pedro struck just before the break.
World player of the year Messi scored twice in as many minutes at the end after the hosts were reduced to 10 men following a second yellow card for Francisco Farinos in the 85th.
"Scoring just before the break helped us a lot but 1-0 is always a dangerous scoreline, any lost ball can put you in danger. The red card for Farinos helped us a lot," Barca coach Pep Guardiola told reporters.
It could have been a different story at the Rico Perez if David Trezeguet had been able to put away a good chance in the 20th minute, as Hercules unsettled the visiting defence.
Barca were knocked out of their stride until Xavi picked out Pedro in the area and the Spain forward thumped a shot inside the near post, scoring for a sixth consecutive league game.
They took the sting out of the encounter after the break but were unable to settle the match until Farinos was sent off and Messi, who had had a poor game by his standards, skipped through to score in the 87th.
Two minutes later, Dani Alves crossed for the Argentine to tap in Barca's third goal, taking his league tally for the season to 21 behind Real's Cristiano Ronaldo on 22.
In the late game, Deportivo La Coruna's Laure grabbed a hotly-disputed late equaliser in a 3-3 draw at home to 10-man Sevilla.
The linesman's flag was up when the full-back broke into the area to score but the referee overruled him prompting heated and lengthy complaints from the visitors. Television replays showed Laure to be onside when he received the ball.
Lassad had put Depor ahead with a spectacular strike early in the first half and, after Sevilla goalkeeper Andres Palop had been sent off for handball outside the area in the 57th minute, he doubled the lead just past the hour.
Sevilla, who have a King's Cup semi-final second leg at Real Madrid on Wednesday, stormed back to take the lead with a double from Alvaro Negredo either side of Julien Escude's opportunist effort, but were denied the three points in the 88th.
Earlier, struggling Sporting Gijon and Real Zaragoza notched their first wins on the road this season to climb away from the foot of the standings.
Sporting's steady improvement was confirmed with a third consecutive victory, beating Real Mallorca 4-0.
They climbed to 12th with 22 points from 21 games ahead of Hercules, Deportivo and 15th-placed Zaragoza on goal difference.
Javier Aguirre's Zaragoza also claimed their third consecutive victory, Florent Sinama Pongolle completing a 2-1 comeback win at Malaga who are now bottom.
Levante, who started the weekend at the foot of the table, won 2-0 at home to Getafe while Real Sociedad sank Almeria 2-0. Levante now have 18 points with Almeria and Malaga on 17.