Vidal poked in a fortuitous goal in the 79th minute at Butarque after Luis Suarez headed home a Lionel Messi free-kick to cancel out a brilliant opener from Leganes forward Youssef En-Nesyri.
Barcelona stay top of the table, three points above Real Madrid, who play later on Saturday at home to La Liga’s surprise high-fliers Real Sociedad.
A gritty win will also come as a relief to under-pressure coach Ernesto Valverde, whose team now turn their attention to Wednesday’s crunch Champions League group game against Borussia Dortmund at Camp Nou.
A goalless draw against Slavia Prague earlier this month means Barca’s qualification from Group F is no longer guaranteed.
After Dortmund, they then play away at Atletico Madrid in La Liga to start a month that will include trips to Inter Milan in the Champions League and Real Sociedad in La Liga before the season’s first Clasico at home to Real Madrid.
It was important therefore to avoid a slip against Leganes, playing their first game in front of their own fans since appointing Javier Aguirre as coach.
The home side made the perfect start as En-Nesyri beat Gerard Pique with a wonderful early striker.
Pique has spent the international break juggling football with the Davis Cup, the revamped tennis tournament in Madrid that he is organising through his marketing company Kosmos.
Doubts about the defender’s focus would not have been allayed in the opening quarter of an hour.
One pass from Roque Mesa was enough to set En-Nesyri free against the 32-year-old in the 12th minute.
Pique jostled but was taken by surprise as En-Nesyri nipped inside and bent a shot into the far corner. Leganes might have had a second soon after and Pique would have been at fault, the defender allowing Martin Braithwaite in after failing to clear, but Oscar Rodriguez was unable to capitalise.
Crosses were a weakness for Leganes as three Barcelona headers all could have gone in. Suarez went close. Pique hit the post. Then Suarez did find the net, glancing in Messi’s clipped free-kick for his ninth goal of the season.
Barca’s second owed much to luck but it came from another cross. Pique rose to head in but the ball missed him and cannoned off the foot of Ruben Perez. Vidal was waiting on the line to prod in.