With Barca trailing 4-2, Messi scored a 90th-minute free-kick before Luis Suarez drilled home a low, half-volley deep into added time to secure a point from a game the LaLiga leaders led 2-0 after 16 minutes.
Philippe Coutinho and Malcom, with his first LaLiga goal, appeared to have laid the foundations for a regulation victory but Samuel Chukwueze, Karl Toko Ekambi, Vicente Iborra and substitute Carlos Bacca turned the game on its head as Villarreal scored four against Barca for the first time since April 2001.
But after Villarreal's Gonzalez Alvaro was shown a second yellow card, the visitors took advantage to earn a draw and ensure they will take an eight-point advantage into the weekend's meeting with second-placed Atletico Madrid.
Atletico extended their lead over city rivals Real to five points with a 2-0 win at home to Girona earlier in the evening.
Koke hit the crossbar with the hosts' best effort of the first half but it took until the 76th minute for them to break the deadlock through defender Diego Godin's close-range header.
Antoine Griezmann's 19th goal of the season deep into added time secured the three points.
Fourth-placed Getafe missed the chance to open up a five-point gap to the chasing Alaves after they were held to a 1-1 draw at Espanyol.
The hosts took a 56th-minute lead through Borja Iglesias but Angel secured a point 18 minutes from time.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies