Jose Mourinho's Real thumped Racing Santander 4-0 on Saturday to put pressure on the champions, who conceded to Pablo Piatti after only nine minutes at the Nou Camp.
World Player of the Year Messi led the fightback with two goals in five minutes to put them ahead by the 27th minute as Pep Guardiola's side responded with some irresistible football.
Messi bagged two more in the second half, taking his league tally to 27, and substitute Xavi lobbed the fifth at the end to move his side on to 51 points from 23 games. Valencia were third with 40.
"The team played a great game," Messi told Spanish television.
"It was important the team played well again like they did in Germany during the week, because the important part of the season is coming and we have to continue in this way."
Espanyol were fourth with 33, ahead of Athletic Bilbao in fifth due to their superior head-to-head record, after the Basques scored three times in three second-half minutes in a 3-0 home win over Malaga.
The King's Cup finalists scored with their first clear sight of goal in the 58th minute when Fernando Amorebieta pounced on a loose ball after a corner, and Mikel San Jose headed the second from another corner.
Gaizka Toquero volleyed in the third at the back post in the 61st.
Atletico Madrid were a point behind them in sixth after being held to a 1-1 draw at Sporting Gijon, who had former Spain boss Javier Clemente in the dugout for his debut at the helm.
Adrian Lopez's cross-cum-shot was turned into his own net by Sporting's Roberto Canella in the 20th minute, but the hosts levelled when Sebastian Eguren poked a loose ball past Thibaut Courtois just before half-time.
Levante slipped down to seventh with 32 points after losing an eight-goal thriller at home to Rayo Vallecano who ran out 5-3 winners.
Earlier, Granada's new coach Abel Resino made it three wins in four since he took the helm when his side came back to beat 10-man Real Sociedad 4-1 at home with a double from Ike Uche.
Villarreal's revival under their new coach Jose Molina shuddered to a halt, however, when they were thrashed 4-0 at Real Mallorca.
At the Nou Camp, Barca were caught napping when Sofiane Feghouli's looping cross was steered in by an unmarked Piatti, but they quickly found their rhythm.
Messi showed great composure waiting for visiting goalkeeper Diego Alves to commit himself before slipping the ball beneath him to level in the 22nd.
The outstanding Andres Iniesta started the move that led to Alves failing to hold Messi's shot in the 27th, and the Argentine pounced to score again, and Cesc Fabregas acrobatically volleyed against the crossbar.
Alves tipped a Messi header on to the crossbar after the break
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.