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.
|Yankees acquire Drury in three-team deal with Diamondbacks, Rays|
|Messi goal will give Barcelona more space at Camp Nou – Suarez|
|Serena Williams: I almost died|
|Conte defends ´incredible´ Christensen after Barcelona error|
|Bayern taking nothing for granted after 5-0 demolition – Heynckes|
|Valverde: Barcelona away goal not definitive for progression|
|Muller & Robben bemoan poor first half despite Bayern rout|
|Ivashka sets up Wawrinka Marseille meeting|
|Chelsea close to a perfect game against Barcelona - Conte|
|Defending for 90 minutes at Barcelona a ´suicide mission´ - Fabregas|
|Championship Review: Villa miss chance to move into promotion places|
|Messi ends his Chelsea hoodoo|
|Texans release all-time leading tackler Brian Cushing|
|Chelsea 1 Barcelona 1: Messi breaks Blues hoodoo to leave tie in the balance|
|Bayern Munich 5 Besiktas 0: Two-goal Muller inspires emphatic win after Vida red|
|Woods and Stricker appointed USA Ryder Cup vice-captains|
|Wales must attack Sexton and Murray - Gatland|
|De Vrij confirms intention to leave Lazio on free transfer|
|Sanchez move down to Champions League frustration at Arsenal - Mourinho|
|Mourinho suggests Pogba is fit to face Sevilla|
|Clinical Kerber strolls past Strycova in Dubai|
|AFC Champions League Review: Hulk & Oscar lead Shanghai, Jeonbuk Motors hit six|
|Cech expects Ospina to start for Arsenal in EFL Cup final|
|Gueye signs new Everton deal until 2022|
|FA charges Man City and Wigan for failing to control players|
|Aguero faces no action over Wigan fan incident|
|Martin released by Buccaneers|
|Las Palmas get green light to sign Viera replacement amid Nasri talk|
|De Kock, De Villiers & Du Plessis looking to Australia Tests|
|FA issues West Ham with anti-doping charge|
|Florenzi a doubt to face Shakhtar, confirms Roma´s Di Francesco|
|Maybe we ´lock him up or tie him up´ – Montella ponders how to stop Sanchez|
|French rugby crisis could last a long time - Magne|
|Pogba and Ibrahimovic train with Man Utd ahead of Sevilla tie|
|Zidane hints at resting Ronaldo for Real Madrid´s trip to Leganes|
|Biggar, Halfpenny and Williams return to Wales´ starting XV|
|Modric adds to Real Madrid injury worries|
|Braehmer pulls out of Super Series semi-final|
|Wolfsburg turn to Labbadia in fight for Bundesliga survival|
|Hales follows Rashid in signing white-ball deal|
|Wigan to investigate pitch invasion after win over Manchester City|
|Drogba ´couldn´t be more proud´ as son signs for Guingamp|
|Stones making no excuses for shock Wigan defeat|
|Bellugi scathing of Inter form and transfer policy|
|Ringrose could make Six Nations impact after comeback|
|Rakitic: I´ve not seen Messi in the gym this often|
|Winter Olympics 2018: Slovenian ice hockey star Jeglic sent home after positive doping test|
|Sevilla v Manchester United: Montella and Mourinho unified in pursuit of identity|
|Besiktas face Bayern test, Messi seeks to end drought - Champions League in Opta numbers|
|Jose Morais: The Mourinho acolyte bringing Barcelona to Barnsley|
|I´ve been bored – Ricciardo itching for start of F1 season|
|Rakitic: More to Chelsea than just Hazard|
|Hosmer agrees to eight-year deal with Padres|
|Cilic untroubled as Fognini battles in Rio|
|Sock, Chung through at Delray Beach|
|Klopp tactics behind my form – Salah|
|Young: Man United can win Champions League|
|Harper refuses to talk free agency, says he´s focused on this season|
|Messi is best but ´not invincible´, says Pedro|
|It´s a red card – Guardiola accepts Delph sending off amid City´s Wigan woe|
|Goffin hopeful of ´fast recovery´ after nasty eye injury|
|Aguero lashes out at fan as tempers flare after Wigan stun Man City|
|Grigg revels in dousing Manchester City´s fire|
|Dzumhur saves four match points to down Kukushkin|
|Wigan Athletic 1 Manchester City 0: Grigg ends Guardiola´s quadruple dream|
|Edinburgh to finish season at Murrayfield|
|Messi the best but don´t forget Suarez, says Chelsea boss Conte|
|I need a great game – Hazard aiming for Messi heights|
|AFC Champions League Review: El-Arabi´s brace seals Al Wahda´s fate|
|Dubai disappointment for Radwanska|