The hosts had fought back with three goals in 11 minutes to lead after trailing 2-0 until the hour mark.
But Villarreal equalised with six minutes remaining and Alexander Sorloth put the visitors back in front in the ninth minute of stoppage time.
Jose Luis Morales then added a fifth after 102 minutes to seal victory.
It comes after they were knocked out of the Copa del Rey quarter-finals in a 4-2 defeat by Athletic Bilbao on Wednesday.
It is Barcelona’s third loss in five matches, with their other defeat in that run coming against Real Madrid in the Spanish Super Cup, which they lost 4-1.
After Gerard Moreno’s first-half opener and Ilias Akhomach’s 54th-minute goal, Barcelona produced a stunning comeback through Ilkay Gundogan, Pedri and an Eric Bailly own-goal.
But, following Goncarlo Guedes’ 84th-minute equaliser for Villarreal, the hosts were left exposed in their pursuit of a late winner and ultimately punished by Sorloth’s and Luis Morales’ late goals.
Real Madrid came from behind to beat Las Palmas 2-1 on Saturday and moved back above Girona, who play struggling Celta Vigo on Sunday (13:00 GMT).