The Uruguayan scored inside the first minute before the Argentine struck in the dying seconds as the visitors were made to pay for a missed penalty
Luis Enrique's team had their lead at the summit cut to two points last weekend when they let a two-goal lead slip in a draw 2-2 at Sevilla.
Barca rediscovered their devastating best form with an emphatic 3-1 Champions League triumph at Paris Saint-Germain in midweek – Luis Suarez starring with a dazzling double.
And Suarez picked up where they left off at Camp Nou on Saturday by firing Barca ahead after 55 seconds.
But the anticipated dominant display did not follow as Valencia spurned numerous chances to equalise, most notable when captain Dani Parejo had a penalty saved and Andre Gomes struck the post.
Barca recovered their poise after half-time and Messi netted his 400th goal for the club in stoppage time, putting pressure on nearest rivals Real Madrid, who host Malaga later on Saturday.
Sergio Busquets was selected in a more advanced position than his customary holding midfield role, with Andres Iniesta an injury absence for Barcelona, and he revelled in this freedom by playing a key part in the opening goal.
Busquets threaded an inch-perfect pass for Messi to race towards a backpedalling Valencia defence and play in Suarez for a clinical low finish.
Valencia forward Rodrigo skipped past Gerard Pique to curl a shot narrowly wide and he drew a foul from the ailing Spain centre-back to win a 10th-minute penalty.
Barcelona goalkeeper Claudio Bravo spared his team-mate's blushes by saving and holding Parejo's tamely struck effort.
The early setbacks did not dent Valencia's confidence – Nicolas Otamendi heading just wide at the far post before Paco Alcacer turned wide from close range and Javier Mascherano produced a vital 22nd-minute block to thwart the same player.
Gomes engineered space on the edge of the area to strike the base of the post after 33 minutes, while Alcacer failed to punish the creaking Barca defence by curling over from 20 yards.
Messi blasted wide at the far post on the end of a move he started five minutes before the break, failing to hand the hosts a second goal they scarcely deserved.
Luis Enrique introduced Ivan Rakitic in place of Adriano at half-time, meaning Mascherano dropped in at centre-back and Jeremy Mathieu moved to left-back against his former club.
Barca played with far greater control after the restart, although Neymar and Messi were unable to make acrobatic efforts count.
Messi curled a sumptuous 64th-minute free kick against the crossbar having been felled by Parejo before Suarez was replaced by Pedro to a standing ovation.
The Camp Nou's other hero of the afternoon, Bravo, displayed excellent reactions to deny Rodrigo following a 75th-minute penalty box scramble.
Pedro rippled the side netting late on but Messi had the final word, striding forward unchallenged on the break to beat Diego Alves at the second attempt and rack up another phenomenal career landmark.