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.
Champions Barcelona's domestic strife continued as they were held to a 1-1 draw at Valencia in an absorbing La Liga game on Sunday, with Lionel Messi again coming to their rescue by equalising with an 11th goal in 10 games this season.
Atletico Madrid defeated Real Betis 1-0 in a tight game on Sunday through a second-half strike from forward Angel Correa as coach Diego Simeone's substitutions paid off.
Sevilla moved provisionally top of La Liga by beating visitors Celta Vigo 2-1 on Sunday for a fourth straight victory that saw them climb above Atletico Madrid, who had led the table for a couple of hours after a 1-0 home win over over Real Betis.
Manu Garcia scored a last-minute winner as Deportivo AlavГ©s beat Real Madrid 1-0 at the Mendizorroza in La Liga.
Real Madrid missed the chance to go two points clear of Barcelona at the top of La Liga as they drew 0-0 with Atletico Madrid on Saturday in an edgy, but entertaining, local derby in which the outstanding players were the two goalkeepers.
Barcelona's run of poor form continued following a surprise 1-1 draw at home to Athletic Bilbao on Saturday.
Real Madrid crashed and burned in a 3-0 defeat at a rampant Sevilla on Wednesday, losing for the first time in La Liga under coach Julen Lopetegui and missing the chance to capitalise on Barcelona's shock 2-1 defeat at Leganes.
La Liga leaders Barcelona slumped to a shock first loss of the season on Wednesday, suffering a 2-1 defeat at struggling Leganes after conceding twice in two second-half minutes as coach Ernesto Valverde's squad rotation backfired.
First-half goals from Antoine Griezmann, Thomas Partey and Koke helped a resurgent Atletico Madrid secure a 3-0 home victory over Huesca in La Liga on Tuesday.