The two teams were level entering the latter stages of the contest at Estadio de la Ceramica before Memphis Depay sent Barcelona 2-1 ahead in the 88th minute.
Philippe Coutinho then made sure of the points with a strike in the fourth minute of added time at the end of the 90, as the Catalan outfit secured back-to-back league successes under Xavi.
The new Barcelona boss has admitted that Villarreal "did not deserve to lose", with the 41-year-old hailing "three golden points" for the club.
"We did not dominate the game as we expected but we played against a great team", Marca quotes Xavi as saying. "We were lucky in parts as Villarreal did not deserve to lose.
"It has taken a lot from us on the night. We have been fortunate with Memphis' goal, but these are three golden points for us."
Barcelona have collected 23 points from their opening 14 matches of the 2021-22 La Liga campaign, which has left them in seventh position in the table. body check tags ::