Atletico Madrid secured third place by winning 2-1 away at Real Sociedad, retaining their one-point lead over Sevilla, who won 1-0 at home to Athletic Bilbao.
Athletic's defeat, combined with Villarreal's excellent victory at Camp Nou, means Villarreal beat Athletic into seventh and qualify for the Europa Conference League.
Villarreal's season was lit up by their sensational run to the semifinals of the Champions League but Unai Emery's team have suffered from inconsistency against the lower sides in LaLiga and will be demoted to Europe's third-tier competition next term.
Athletic finished eighth while Real Sociedad held onto sixth and Europa League qualification, despite their loss at home to Atletico Madrid.
Barca already had second place and a spot in the top four wrapped up but Xavi Hernandez will be concerned heading into the summer about how his team has faded.
Defeat by Villarreal means Barcelona lost four of their last nine games in all competitions while Real Madrid won LaLiga at a canter.
After being appointed in November, with the team lying ninth, Xavi revived the team and achieved the most important objective of qualifying for the Champions League.
But going out to Frankfurt in the Europa League semifinals and Athletic Bilbao in the Copa del Rey was disappointing while the drop-off during the run-in suggests there is still a lot of work to do.
Villarreal's two goals came either side of halftime as Alfonso Pedraza scored in the 41st minute after latching onto a Dani Parejo through-ball before Moi Gomez made it two in the 55th.
Adama Traore was at fault, his attempted clearance across his own box falling straight to Gomez, who fired in, with Traore substituted immediately after.