Barcelona 4-2 Valencia
Eliaquim Mangala headed the visitors in front from a corner, before Luis Suarez steered in an equaliser.
Messi's penalty made it 2-1 after Manchester City loanee Mangala was sent off for dragging back Suarez, but Munir El Haddadi swept Valencia level.
Luis Enrique's three-man back line was caught out too often, with Munir denied by keeper Marc-Andre ter Stegen when clean through seconds before Mangala scored from the resulting corner.
Enrique, though, had plenty of reason to fume when his own defenders allowed Munir, on loan from Barcelona, all the time he wanted to turn in Jose Luis Gaya's pull-back.
In the end, they settled for two in the second half; Messi - La Liga's leading scorer - caught out keeper Diego Alves with a near-post drive and substitute Gomes tapped in from Neymar's pass.