Gabriel Paulista gave Valencia the lead but Messi equalised after seeing his penalty saved. Antoine Griezmann then put Barca ahead before Messi curled home a brilliant free-kick. Carlos Soler grabbed a consolation with a stunning long-ranger.
The result means Barcelona remain in the title hunt with four games remaining, ahead of their big match against leaders Atletico Madrid next week.
Here are some of the players who stood out most on Sunday.
✔️ Carlos Soler: 7.5
He provided the assist for Gabriel Paulista to put Valencia ahead and then reopened the game at 1-3 with a stunning goal of his own.
The 24-year-old unleashed a thunderous long-range strike that flew into the top corner past Andre Ter Stegen.
He now has nine goals and six assists in 28 games.
❌ Toni Lato: 5.1
Valencia had looked on course for an unlikely victory after taking the lead in the 50th minute through former Arsenal defender Gabriel Paulista.
However, their chances were ruined by a moment of stupidity from Toni Lato.
The left back crazily stuck out his hand in the penalty area after the ball had been chipped into the box, leaving the referee no choice but to award a penalty.
Although Messi saw his initial spot-kick saved, the little Argentine did eventually equalise seconds later. Barcelona were always going to win from that moment on and Lato was hauled off on 64 minutes.
⭐️ Lionel Messi: 9.5
Unsurprisingly, Messi was named man-of-the-match for the 22nd time this season.
This means that he has been the best player on the park in exactly half of Barcelona's games this campaign.
He rescued Barcelona on Sunday, first of all turning home from close range shortly after his penalty had been saved by Jasper Cillessen.
The 33-year-old then made the game safe on 69 minutes with a magnificent free-kick, curling the ball over the wall and in the top corner.
Messi's magic will increase the calls for him to sign a new contract, with his current deal expiring at the end of the season.