The Barcelona goals came after the jolt of conceding early in the second half when Gabriel Paulista headed in from a corner to give the hosts the lead, with visiting boss Ronald Koeman banned from the touchline after his dismissal in the shock defeat to Granada.
Carlos Soler drove in a spectacular late second for Valencia, but Barcelona's success means they are back to just two points behind Atletico, and level again with Real Madrid, as the saga of the title race heads for a thrilling conclusion.
81,25% - @FCBarcelona have claimed #LaLiga Champions in 13 out of their 16 seasons when they collected at least 74 points after 34 games played (81,25%). They only failed in 2012, 2014 & 2017. Fighter#valenciabarca pic.twitter.com/J2iIPARWtO— OptaJose (@OptaJose) May 2, 2021
Pedri wasted a great chance in the third minute as he shot wide of the right post after being teed up by Frenkie de Jong, and Ronald Araujo's effort on the stretch from a teasing Messi free-kick was blocked away by goalkeeper Jasper Cillessen.
Valencia's Goncalo Guedes should have scored early in the second half but allowed Marc-Andre ter Stegen to push his shot wide for a corner. However, Gabriel made no mistake when Soler swept the set-piece delivery across from the left, heading in at the far post.
Barcelona drew level in the 57th minute through Messi, despite him failing from the spot. Toni Lato conceded the spot-kick after jabbing his right arm at a floated Messi pass, and although the Argentinian saw his tame penalty parried by Cillessen, Pedri's shot as the ball pinged around the box was deflected to Barcelona's record scorer, who netted from close range.
The visitors went ahead six minutes later when De Jong's powerful header from Jordi Alba's cross was well saved by Cillessen but palmed only as far as Griezmann, who tucked home.
Messi's second goal was a 69th-minute curling free-kick from a central starting point that found the back of the net via the inside of the right post, giving the goalkeeper little chance, a speciality of Barca's captain.
It was arguably topped by Soler's brilliant long-range finish in the 83rd minute, but Valencia could not find a leveler.