Barca got 2017 off to a losing start thanks to a 2-1 Copa del Rey defeat to Athletic Bilbao and it was unable to chalk up their first win of the year at the renamed Estadio de la Ceramica.
Despite dominating possession in the opening period, Barca reached half-time with the scoreline goalless for the fifth time in six league matches.
And Nicola Sansone scored the game's opening goal after 49 minutes, capping a rapid Villarreal counter-attack.
A trio of penalty appeals – two for Barca and one for Villarreal – were ignored before a free-kick on the edge of the box opened the door for Messi to snatch a share of the spoils.
And the Argentina international, who had earlier hit the post, wrong-footed goalkeeper Sergio Asenjo as he fired into the top left-hand corner.
Villarreal's Jaume Costa was sent off in stoppage time for a second yellow card as its hopes of entering the UEFA Champions League qualification spots were scuppered.
The result leaves third-placed Barcelona five points adrift of Madrid, which has a game in hand.
Ivan Rakitic was absent from the Barcelona squad amid rumours of interest from Manchester City, although the club earlier insisted the Croatian's omission was for "technical reasons".
Andres Iniesta drew a save from Asenjo with a long-range strike inside the opening three minutes, before Neymar and Luis Suarez both went close.
Jonathan dos Santos' volley just over was a reminder of Villarreal's qualities at the other end, and Sansone subsequently forced Marc-Andre ter Stegen into two saves.
Neymar then arrowed a right-footed strike just wide from 20 yards, having impressively forced open a space to get the shot away.
Villarreal was reliant on the strength of its counter-attacking skills as Barca dominated possession, and a Messi header and low Suarez drive called Asenjo into action before the interval.
It was a dangerous break that led to the hosts' opener.
Roberto Soriano intercepted a loose Barca pass before Alexandre Pato surged downfield and played in Sansone, who sent a low strike across Ter Stegen and just inside the left-hand post.
Neymar came close to an instant reply when he was denied from close range by Asenjo after a well-worked free-kick, before Messi saw an effort agonisingly come back off the inside of the post with the goalkeeper beaten.
With Neymar having seen an earlier appeal for a penalty turned down after going down in the box, Villarreal felt it should have had a spot-kick of its own when a Soriano strike appeared to hit Javier Mascherano on the hand.
Barca then had more vociferous calls for a penalty waved away for a handball against Bruno, before a 90th-minute foul on Messi on the edge of the box gave the Catalans a late chance to snatch a point.
And Messi stepped up to the plate with a superbly taken set-piece, although his efforts only minimise the damage done by more dropped points in Barca's title challenge.