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.
22. August 2018
|England captain Hartley ready for return|
21. August 2018
|Buttler happy to serve up a century as England dig in at Trent Bridge|
|PSV beat BATE in Champions League thriller, Benfica held at home|
|Mkhitaryan backs Emery´s philosophy at Arsenal|
|Championship Review: Leeds go top, QPR problems mount|
|Ronaldo shares snap of ´Juventus family´|
|Aguero is the Premier League´s best foreign import, says Shearer|
|Real Madrid warned they must pay Rodrigo´s €120m release clause|
|England´s Broad fined for Pant rant|
|India on brink of victory after brilliant Bumrah halts Buttler|
|Serena Williams elevated to 17th seed at US Open|
|Kombouare signs new two-year Guingamp contract|
|Scaloni unclear on Messi´s long-term Argentina plans|
|F1 Raceweek: Gasly and Alonso restore focus at Spa|
|Nouri able to communicate, brother reveals|
|Pjanic extends Juventus contract to 2023|
|Odegaard joins Vitesse in latest loan from Real Madrid|
|Luck ´sort of happy´ with sack from Suggs|
|Manchester United´s Sanchez will ´be back soon´|
|Former Giants star Cruz announces retirement|
|RFU set Cipriani disciplinary date despite RPA complaints|
|Spalletti fined €10,000 for ´gravely offensive´ referee comments|
|IndyCar driver Wickens has spinal surgery after Pocono crash|
|Tiger: No doubt this is one of my best years|
|Vice-captain Tiger trying to remain objective in Ryder Cup conversations|
|Ronaldo won´t win Serie A by himself, warns Allan|
|Moeen sends message to England selectors with double century|
|Brunt calls time on Northern Ireland career|
|Tottenham´s Janssen sidelined after foot surgery|
|Liu Xiang breaks women´s 50m backstroke world record at Asian Games|
|Atletico Madrid winger Vitolo suffers knee ligament damage|
|Leverkusen teen Havertz aiming to emulate idol Ozil|
|Beckham to be honoured with UEFA President´s Award|
|CPS drops Hillsborough charges against Bettison|
|Who can take over from Federer, Nadal & Djokovic? Agassi backs Zverev, Kyrgios|
|´Freak incident´ rules Dragons´ Vaughan out for season|
|Kompany: Different Manchester City must not be complacent|
|Toyota withdraw appeal over Alonso´s Silverstone disqualification|
|Manchester City offload defender Denayer to Lyon|
|RPA want RFU to drop Cipriani charge|
|Cheika still the right man for Australia - Polota-Nau|
|Bolt not giving up on Manchester United dream|
|All Blacks must improve ´average´ set-piece, says Smith|
|Raiola hits back at Scholes following Pogba criticism|
|Indians top Red Sox in series opener|
|Struff stuns Cecchinato, Jarry reaches last 16|
|I´ll prove people wrong - Bolt completes first Mariners training session|
|Former champ Kvitova tops Radwanska, Pliskova ousted|
|Sad if it´s Filipe Luis´ last game for Atletico - Oblak|
|White Sox manager Rick Renteria hospitalised before game|
|Carragher: Van Dijk can become Liverpool legend|
|No timetable for Sale return from shoulder injury|
|This is a partnership - Rodgers on contract negotiations with Packers|
|Eagles QB Wentz unsure he´ll be cleared to play opener|
|Balotelli staying at Nice|
|It wasn´t a penalty, says Hodgson as Palace boss fumes at refereeing decisions|
|Salah can play much better - Klopp demands more from Liverpool star|
|Gasly to Red Bull: Vettel, Verstappen and the drivers who took their Toro Rosso chance|
|Klopp in the dark on Karius future amid links to Besiktas|
|Simeone pleased with draw after rigours of Super Cup|
20. August 2018
|Captain Reus saves Dortmund in DFB-Pokal|
|I couldn´t care less - Klopp rejects title challenge talk|
|Ailing Bairstow keen to aid England´s unlikely victory bid at Trent Bridge|
|Redskins secure Peterson signing|
|Manchester City goalkeeper Bravo suffers ruptured Achilles|
|Crystal Palace 0 Liverpool 2: Milner and Mane secure victory at Selhurst Park|
|Whyte takes aim at ´coward´ Fury ahead of Wilder showdown|
|Jets delighted with Darnold, open to trading Bridgewater|
|Gasly to replace Ricciardo at Red Bull|
|Valencia 1 Atletico Madrid 1: Rodrigo strikes to deny Simeone´s side|