Barcelona's needed a 90th-minute penalty from Lionel Messi to overcome 17th-placed Leganes 2-1 in La Liga on Sunday.
Messi put the hosts up almost right out of the gates, striking from close range in the fourth minute, with Luis Suarez providing the assist.
But, with Barca trying to extend the lead, the visitors found a shock equaliser in the 71st minute, when Darwin Machis found Unai Lopez, who slotted home from the centre of the penalty area past Marc-Andre ter Stegen.
With time running out, Neymar drew a foul in the penalty area to give Messi the chance, and the Argentine came through to spare his team blushes and rescue all three points.
The Liga holders, who moved back into second place ahead of Sevilla with the win, were embarrassed by Paris Saint-Germain on Tuesday, losing 4-0 in the first leg of the teams' round-of-16 tie.
The playmaking of new arrival Fabian Orellana inspired Valencia to a much-needed 2-0 victory over Athletic Bilbao at the Mestalla.
Orellana's precise pass through Bilbao's back line set up Nani for Valencia's opener in the 13th minute.
Orellana, who joined from Celta Vigo last month, combined with Munir El Haddadi in a brilliant buildup that ended with fellow winter transfer signing Simone Zaza doubling the lead in the 45th.
Bilbao were left with 10 men from the 56th minute when substitute Aritz Aduriz was injured three minutes after coming on. Bilbao coach Ernesto Valverde was unable to replace him because he had made all three substitutions.
A stoppage-time goal by Samuel Castillejo gave Villarreal a 1-0 win at Real Sociedad as the Yellow Submarine rebounded from their 4-0 loss to Roma in the Europa League's round-of-32 first leg.
"We needed this win," said Castillejo, who scored from a pass by Jaume Costa. "The loss to Roma hurt a lot."
Sociedad and Villarreal remained in fifth and sixth place, respectively.
Giuseppe Rossi helped Celta Vigo beat bottom-side Osasuna with a deft touch of his heel to set up Pione Sisto for the opening goal.
Jozabed Sanchez struck in the 87th before passing for fellow substitute Iago Aspas to chip in his 12th goal of the season.
Osasuna's winless streak reached 15 rounds as the Pamplona-based side fell eight points from safety.