Valencia took the lead through Mouctar Diakhaby's header on 29 minutes, but Messi pulled Barca level deep into first-half stoppage time.
Referee Alejandro Hernandez Hernandez pointed to the spot and issued Valencia captain Jose Gaya a red card following a push on Antoine Griezmann in the box. However, after consulting with the VAR, he downgraded the card to a yellow.
Messi stepped up but saw his penalty saved by goalkeeper Jaume Domenech. Valencia failed to clear and Messi was on hand to head home his historic goal from close range. Pele scored 643 goals with Brazilian side Santos before a brief and memorable stint with the New York Cosmos.
The result leaves Ronald Koeman's side eight points adrift of leaders Atletico Madrid, who have played a game less.
"It was a difficult game, we turned it around but then we needed to show more concentration," Koeman said after the match.
"We had some chances but we were not focused enough in key moments. We went out to win the game in the second half but we did not create as much as we wanted to."
The Dutch coach was particularly annoyed with how his side failed to pick up Diakhaby for the opening goal, saying they needed to focus more on defensive organisation due to their low average height.
"We have to know how many tall plays we have to defend against tall players. He [Diakhaby] was all alone when he jumped up to score. We have to defend better and mark our opponents more. We're smaller than most teams and we have problems at set pieces," he said.
"We gave an inconsistent performance. We attacked when we were 2-1 up but we also need to remember to defend. We lost the ball in dangerous areas."
However, he refused to rule his side out of the title race.
"The age of the players also has an influence, sometimes doubt can set in. The young players need to mature," he said.
"We still haven't said farewell to the title, there's still a lot of points to play for. It's a very difficult season but in two months everything could be different. We have to fight to get these points back."
"We're feeling bitter because we really wanted the three points, it's a real shame they equalised," goalscorer Araujo said after the match.
"We made some mistakes in defence which we cannot afford to make and it's very frustrating because we had lots of chances but the ball wouldn't go in."
Information from Reuters was used in this report