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.
|Croatia´s Lovren antagonises Ramos and ´rude´ Spain|
|Rakitic has ´enormous respect´ for England ahead of Nations League decider|
|Ireland make flanker switch with Leavy out of All Blacks clash|
|Pakistan rip through Black Caps in Abu Dhabi|
|WATCH: Barcelona mark 15-year anniversary of Messi´s first match|
|Sterling, that you? - Walker uses falling fan to poke fun at England team-mate|
|Fleetwood applies pressure on Molinari, Wallace leads in Dubai|
|Don´t talk to me about VAR – Rakitic not over World Cup final loss|
|Van Dijk leadership essential for Liverpool – Wijnaldum|
|Dalic: Croatia´s bench was ready to stop Spain!|
|Sublime Root century gives England imposing lead|
|Vinicius appreciates Solari influence at Real Madrid|
|Havertz would suit Bayern Munich – Kimmich|
|Wilder: Roach recruitment a sign of Fury nerves|
|Ranieri targets defensive improvements at failing Fulham|
|PSG close investigation into player recruitment practices after finding no discrimination|
|Mayweather: Nasukawa exhibition back on|
|Witsel: Joining Borussia Dortmund my best career decision|
|Ballon d´Or win would not change Modric´s ´best year´|
|Ireland v New Zealand: Opta stats behind the meeting of the world´s top two|
|The Breakdown: A statistical look at Saturday´s rugby internationals|
|Batshuayi dismisses reports of Valencia departure|
|Brazil must make Copa America final – Tite|
|Rockets rout Warriors as Green goes scoreless|
|Seahawks rally past Packers|
|Lakers G Rondo to miss 4-5 weeks|
|Durant is done with questions about Green|
|Smith, Warner set to return to IPL in 2019|
|No rivalry between Mbappe and Griezmann – Deschamps|
|Neymar: Emery will bring success to Arsenal|
|Jedvaj backs Croatia to deliver against England|
|Howell grabs first-round lead at Sea Island|
|Rooney backing Kane to break England record|
|Betts named American League MVP|
|Republic of Ireland must improve, says under-pressure O´Neill|
|Injured Sergio Ramos to leave Spain squad|
|Yelich named National League MVP|
|Low praises ´beautiful goals´ from Sane and Gnabry|
|Belgium boss Martinez pleased with patient Batshuayi|
|Wilson and Sancho pay tribute to England ´legend´ Rooney|
|Rooney gave England squad a lesson in humility - Southgate|
|This Week in U.S. Sports: LeBron passes Chamberlain, Williamson looking like he is next|
|We still have a chance - Luis Enrique not giving up hope after Spain defeat|
|Rockets ´parting ways´ with Anthony|
|Rooney became ´embarrassed´ at Manchester United|
|Federer: ´Easier´ to play when I´m up against it|
|Rooney convinced England are in safe hands with Southgate|
|Black Caps skipper Williamson confident over first Test availability|
|Federer cruises into last four of ATP Finals for 15th time|
|Republic of Ireland 0 Northern Ireland 0: Randolph saves light up bore draw|
|England 3 United States 0: Experimental side impresses on Rooney farewell|
|Croatia 3 Spain 2: Jedvaj keeps World Cup finalists in contention|
|Belgium 2 Iceland 0: Batshuayi rekindles Hazard flame with match-winning brace|
|Germany 3 Russia 0: Sane on target as Low´s men stroll|
|´Fancy taking a look at Brexit?´ - Southampton credit Austin with VAR breakthrough|
|Green: Altercation with Durant will make Warriors stronger|
|Juventus star Dybala dismisses Manchester United links|
|Strinic given all clear to return to AC Milan training|
|Papier wait over as scrum-half starts for Springboks|
|MLB commissioner Manfred gets five-year extension|
|South Africa international Du Preez joins brother at Sale|
|Pogba and Sterling support my football dream, says Bolt|
|Asensio wants to ´feel more important´ at Real Madrid|
|Former Roosters and Cowboys centre Linnett joins Hull KR|
|New team tournament ATP Cup wins Djokovic´s approval|
|Roma and Pallotta donate €150,000 to injured Liverpool fan Sean Cox|
|England captain Root reprimanded on frustrating day in Pallekele|
|Jokanovic proud of establishing Fulham´s ´footballing identity´|
|Huget to make first France appearance in a year|
|Mourinho and squad ´united´ despite ´mixed´ start, says Woodward|