Barcelona was facing another stumble on the road when Memphis Depay came to the rescue.
The Netherlands striker scored just in time to defuse a Villarreal comeback and secure Barcelona's 3-1 victory on Saturday, and end his team's winless record in the Spanish league.
Seeing his team struggle to keep possession in the final minutes, goalkeeper Marc-Andre ter Stegen broke with Barcelona's stylebook of working the ball forward with small passes.
Instead, he surprised Villarreal with a long goal kick that Depay ran onto and won against two defenders. Depay then coolly dribbled around goalkeeper Gerónimo Rulli before slotting the ball between the legs of Gerónimo Rulli for the 88th-minute decider.
Philippe Coutinho sealed the much-needed win with a penalty that he earned in stoppage time.
“We played against a great team. We dominated the ball less than I had expected, but we were fortunate to get that goal from Memphis,” said Xavi Hernández, who coached his first away game since replacing Ronald Koeman.
“These are three golden points, the first win away from home. We suffered and we need to improve. We got lucky.” Depay, who arrived as a free agent this summer from Lyon as cash-strapped Barcelona tried to rebuild on the cheap, has eight league goals, second only to the 10 by Real Madrid's Karim Benzema.
Barcelona stayed in seventh place, but reduced the gap to leader Real Madrid to seven points. Madrid faces a tough test on Sunday when it hosts third-placed Sevilla.
Second-placed Real Sociedad will also visit Espanyol on Sunday, while fourth-placed Atlético Madrid is at Cádiz.
DE JONG LEADS
With Frenkie de Jong as playmaker, Barcelona looked set for a romp, only to be stopped by the same finishing troubles that have plagued it since the exit of Lionel Messi.
De Jong found Depay in the box, who laid the ball off for Gavi Páez to hit the far post with a shot from a tight angle. Moments later, Depay squandered a wonderfully weighted pass from De Jong that his Dutch teammate scuffed wide.
De Jong finally broke through for the visitors three minutes after halftime when he finished off a ball saved by Rulli.
Then the same second-half defensive problems that doomed Koeman again emerged for Xavi's team.
Villarreal substitute Samuel Chukwueze equalized in the 76th when he fired in a pass by Manuel Trigueras after Barcelona lost the ball from a throw-in near midfield. Trigueros and Arnaut Danjuma both went close as Villarreal attacked in waves that relented only when Depay struck the other way.
Unai Emery's Villarreal remained 12th.