Messi was making his first start of the 2019-20 campaign after recovering from a calf problem that dogged him during pre-season.
The club captain set up Barca's opener in a 2-1 win by delivering a corner for Antoine Griezmann to flick home a header.
But after a hefty challenge Messi was left in discomfort, the forward receiving treatment on the touchline before returning to the field.
Messi, though, did not return for the second half as coach Ernesto Valverde sent on Ousmane Dembele in his place at the interval.
Valverde told reporters he took Messi off as a precaution and while Barca have not given details of the injury he suffered, a club statement confirmed it affected his left leg.
"The player of the first team Leo Messi has an elongation to the adductor of the left thigh," said a club medical update.
Messi, who was making his 400th LaLiga start against Villarreal, could be a doubt for Saturday's LaLiga trip to Getafe.
Valverde's men are then in Champions League action at home to Inter on October 2 before hosting Sevilla in their last LaLiga game before the October international break.
Barcelona face Real Madrid in the first Clasico of the 2019-20 LaLiga season at Camp Nou on October 26.