Marco Asensio struck a last-gasp winner as Real Madrid edged to a 1-0 win at Leganes in the first leg of their Copa del Rey quarter-final on Thursday.
Zinedine Zidane's men, 19 points behind Barcelona in LaLiga, had won one of their last five games in all competitions, amid reports the Frenchman could leave the club at the end of the season, and they looked set to be held at Butarque.
But after Leganes had shone on their first appearance at this stage of the competition, Asensio came up with a cute near-post finish from Theo Hernandez's cross to put Madrid in firm control of the tie.
Madrid were held at home by lower-tier clubs Numancia and Fuenlabrada in previous rounds after first-leg away wins and they struggled to respond to Saturday's 1-0 defeat at the hands of Villarreal, with Mateo Kovacic missing a golden first-half chance.
Jose Naranjo and Claudio Beauvue forced smart stops from Kiko Casilla and Marcos Llorente headed against his own crossbar, adding to the sense of injustice at Leganes' defeat.
Madrid were poor for large parts of the contest, but Asensio's dramatic impact may serve to ease the growing pressure on Zidane ahead of Wednesday's return leg at the Santiago Bernabeu.
GOLAZOOOOOOOOOO! What a goal!!! @TheoHernandez produced an excellent cross from the left and @marcoasensio10 expertly volleyed home, at the near-post, from iust outside the six-yard box!@CDLeganes 0-1 #RealMadrid#RMCopa | #HalaMadrid— Real Madrid C.F. (@realmadriden) January 18, 2018
Madrid were forced into an early change, introducing birthday boy Nacho at the back for the injured Jesus Vallejo, but Zidane's men made a flat start to the game and had to wait until the 23rd minute for a sight of goal, which Raphael Varane headed over the crossbar.
Javier Eraso rifled a long-range drive off-target as Leganes, on a four-game winning streak at home, found a foothold in midfield midway through the first half.
But Madrid should have taken the lead when Kovacic picked Ruben Perez's pocket 25 yards from goal, only for the Croatian to slide his shot tamely wide of the near post.
Gerard Gumbau got a vital touch to deflect Dani Carvajal's drive wide before Lucas Vazquez just missed Asensio's cross on the stroke of half-time.
Casilla had to react sharply to block a close-range Naranjo effort after 56 minutes, Diego Rico nutmegging Carvajal with a superb backheel to send the winger clear.
And Leganes came even closer to breaking the deadlock when Llorente could only direct a free-kick against the woodwork, with Casilla stranded.
Zidane brought on Luka Modric and Isco for more midfield control but Leganes substitute Nordin Amrabat had a more immediate impact, hooking a volley wide moments after his introduction.
With the game becoming stretched, Modric played Vazquez through but Nereo Champagne made a fine block, denying the Spain winger his fourth goal in the competition.
Casilla sharply palmed away a Beauvue volley destined to fly inside his left-hand post with 15 minutes to go and when Kovacic again finished meekly, Leganes looked to have held on.
It was not to be.
Clumsy for the most part, Theo had endured a poor game at left-back but his whipped delivery was perfect for Asensio to get in front of his man to flick home a vital goal for Zidane's Madrid.
|Canelo ready to leave comfort zone to face Fielding|
|Eriksen ready for Tottenham return, Pochettino confirms|
|Titans coach rocked by Hurrell´s Rhinos switch|
|Rubin Kazan suspended from UEFA competition for FFP breach|
|Real Madrid could sack Lopetegui if results don´t improve, says Essien|
|On-court coaching would add to drama - Mouratoglou|
|Babbel lauds ´top class´ Ronaldo after Juventus switch|
|Carmelo Anthony: Rockets bench role challenging mentally|
|Maqsood preferred to Amir in Pakistan T20 squad|
|Make Ramsey Arsenal captain, don´t let him leave – Wilshere|
|Kaneria admits guilt in spot-fixing case|
|No coach can work miracles – Ibrahimovic defends under-fire Mourinho|
|Morgan earns England recall, Cipriani overlooked|
|Reavie leads CJ Cup, solid start from Koepka|
|Juventus kicked me out to sign Ronaldo – Higuain|
|England forward Hughes given six-week ban|
|Injured Halep withdraws from WTA Finals|
|Ronaldo exit makes all the difference for Real Madrid – Luxemburgo|
|Manchester United´s Chelsea Blues and other one-sided rivalries|
|Babbel fears for Kovac´s Bayern future|
|Bradley homers again, Red Sox take 3-1 lead over Astros|
|Ayton, Doncic shine on NBA debuts|
|Leonard focusing on future after Raptors debut|
|MLS Review: Rooney stunner seals DC win, Sounders clinch play-off spot|
|Pochettino ´proud´ of Dier for Ramos tackle|
|Wallabies name three uncapped players for All Blacks clash|
|Lakers coach Walton will monitor LeBron´s minutes, plans to use deep rotation|
|Lloris: United´s Pogba unfairly judged because of transfer fee|
|´Phenomenon´ Mbappe deserves Ballon d´Or, says Buffon|
|Dodgers on cusp of World Series after beating Brewers|
|Mata braced for ´difficult month´ at Man United|
|WATCH: Rooney scores wonderful free-kick for DC United|
|Kaino handed five-week ban for striking Roberts|
|Bears star Khalil Mack ´day-to-day´ with ankle injury|
|Anthony has ´a clearer understanding´ of his role with Rockets|
|Brewers remove Miley after one batter against Dodgers|
|Rams rule out Kupp for 49ers game|
|Giants owner Mara to talk with Beckham Jr|
|Bamberg battle back to claim Champions League win|
|MLB investigated alleged Astros sign stealing, found no wrongdoing|
|Timberwolves star Wiggins to donate $22 for every point this NBA season|
|Red Sox´s Sale won´t start game five of ALCS|
|Tsitsipas and Shapovalov advance at Stockholm Open|
|Witsel to Dortmund is signing of the season - Martinez|
|Pique confident Nadal will play in 2019 Davis Cup|
|Seeds suffer in Moscow and Luxembourg|
|Johnstone grabs hat-trick as England ease past France|
|Pogba and Mourinho disagreement over Instagram video, confirms Pereira|
|Nuggets coach Malone signs contract extension|
|Mayweather accepts Khabib´s challenge: ´We´re fighting´|
|Slovenia sack Kavcic as head coach|
|Morgan and Rashid star as England win rain-reduced ODI in Sri Lanka|
|Romagnoli aims to make Gattuso proud in Milan derby|
|Naldo signs Schalke extension|
|Bills to start quarterback Anderson against Colts with Allen out|
|O´Sullivan makes 147 at ´hellhole´|
|Barcelona know when captain Messi is angry – Abidal|
|Bertens loss hands Pliskova last WTA Finals berth|
|Liverpool star Mane undergoes hand surgery|
|F1 Raceweek: Happy hunting ground for title-chasing Hamilton - US GP in numbers|
|Canelo signs record-breaking DAZN deal|
|England hit by another Vunipola injury absence|
|Gruden: Oakland Raiders ´aren´t tanking´|
|Chiesa focused and happy at Fiorentina|
|We´ll see what´s possible - Henry not limiting Monaco´s ambitions|
|Wembley sale off after Khan offer withdrawn|
|Football needs people like Arsene - Pires keen for Wenger return|
|Abbas five-for torments woeful Australia as Pakistan take control|
|Henry: Wenger and Guardiola inspirations for my coaching career|
|Pires backs Henry and Vieira for Ligue 1 success|