Marco Asensio's late strike earned Real Madrid a 1-0 first-leg lead in their Copa del Rey quarterfinal with Leganes.
Mateo Kovavic spurned a great opportunity for Real, whose goalkeeper Kiko Casilla made a good save to deny Claudio Beauvue after 75 minutes.
And Real took advantage after 89 minutes when Theo Hernandez's cross was met by Asensio's fine volley from six yards out.
The win at the Estadio Municipal de Butarque in the outskirts of Madrid gives Real an advantage ahead of next Wednesday's second leg at the Bernabeu and will come as a relief after recent results.
It was only Real's second win of 2018 and the first came in the same competition, a 3-0 victory at Numancia on Jan. 4.
Zinedine Zidane's men next play Deportivo La Coruna on Sunday in LaLiga, where they sit an unfamiliar fourth, 19 points behind leaders Barcelona and 10 adrift of second-placed Atletico.
Real head coach Zidane selected only Dani Carvajal and Raphael Varane of his first-team regulars to face their fellow La Liga outfit.
A further change was necessary after 15 minutes, when Jesus Vallejo went off injured, with Nacho coming on.
The visitors, as anticipated, dominated possession. But they had little to show for their efforts.
Varane headed over from Asensio's free kick, but few chances were fashioned by Real.
Kovavic nipped in after Ruben Perez mis-controlled on the edge of the area.
The Croatian faced only home goalkeeper Nereo Champagne, but lost his composure, shooting wide before holding his head in his hands.
Beauvue was often isolated for Leganes, who proved difficult for Real to break down.
Asensio tried to create something, only for Champagne to divert the danger.
And Zidane called for reinforcements, with Luka Modric sent on from the bench for Dani Ceballos.
It was a Leganes substitute who nearly had an immediate impact, though.
On-loan Watford winger Nordin Amrabat met Diego Rico's deep cross on the volley, but fired wide of the post.
Lucas Vazquez and Modric combined well on the right, but Champagne smothered the former's effort.
Then Casilla was called upon. Amrabat raced on to the ball down the left and lofted a pass to Beauvue.
The striker hit the ball cleanly, but Casilla was equal to the shot, turning the ball around the post for a corner.
Real were roused. And the visitors took the lead when Hernandez crossed from the left and Asensio struck.