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.
|Zverev destroys racquet in Aus Open meltdown|
|From Villarreal to Aus Open quarters – Bautista Agut breaks major duck|
|Brees: I plan on being here next year and making another run at it|
|´Unf******-believable bro!´ - Brady stunned after reaching third straight Super Bowl|
|New England find answers, penalty costs Kansas City – three takeaways from Patriots´ win over Chiefs|
|Donald Trump congratulates Brady and Super Bowl-bound Patriots|
|Rose helps Timberwolves down Suns|
|Brady leads Patriots into third straight Super Bowl|
|Osaka overcomes Sevastova to reach quarters|
|Chelsea remain behind Sarri – David Luiz|
|McVay explains Gurley´s limited role in Rams´ win over Saints|
|Southgate hails ´tremendous talent´ Rashford|
|Long earns maiden PGA Tour win at Desert Classic|
|Flanagan resigns as Sharks head coach|
|Rams´ Robey-Coleman admits he committed penalty on controversial no-call|
|NFL admits they blew the call – Saints coach Payton|
|Terrible no-call, Goff shines – three takeaways from Rams´ win over Saints|
|Lonzo Ball to miss 4-6 weeks with ankle sprain|
|Patterson added to Australia Test squad|
|Zuerlein´s overtime kick sinks Saints and sends Rams to Super Bowl|
|It was a clear goal – Valverde dismisses Barca VAR controversy|
|Rashford can emulate Man United greats Ronaldo and Rooney – Solskjaer|
|Karmichael Hunt swaps Reds for Waratahs|
|Barcelona forward Dembele set for tests on sprained ankle|
|Neymar insists Barcelona and Real Madrid links not ´concrete´|
|England trio Nowell, Slade and Cowan-Dickie sign fresh Exeter deals|
|Windies coach Pybus not distracted by detractors|
|Barcelona 3 Leganes 1: Messi and Suarez combine to spare Barca´s blushes|
|I´m sure Michael would be extremely proud - Vettel hails Mick Schumacher|
|Young plays down injury fears for England trio Launchbury, Shields and Hughes|
|Pochettino: Lucas Moura fit for Chelsea clash|
|Ranieri positive on Fulham survival chances despite ´unbelievable´ Spurs loss|
|United Arab Emirates v Kyrgyzstan: Zaccheroni confident in attack|
|South Korea lose Ki to hamstring injury|
|It doesn´t look great - Pochettino to wait on Alli assessment|
|Messi benched as Barcelona face Leganes|
|Dalglish texts me before matches - Van Dijk|
|Patrick Mahomes could sign NFL´s first $200m contract - reports|
|Iran 2 Oman 0: Jahanbakhsh and Dejagah secure last-eight spot|
|Helloooo u remember me? Nkoudou reminds Spurs fans he exists|
|Japan v Saudi Arabia: Pizzi believes Saudis can upset the odds|
|Repsol Honda´s Lorenzo to have surgery on fractured wrist|
|Fulham 1 Tottenham 2: Winks heads late winner after Alli injury|
|Leinster seal home quarter-final with win over Wasps|
|Vince, Curran star as Sixers trounce Heat to move second|
|Sharapova stunned by Barty as Kvitova takes Anisimova to school|
|Guardiola demands improvement after Man City win|
|Sexton has bat phone to referees - Jones|
|Alonso accepts Chelsea guilty of ´silly mistakes´ in Arsenal defeat|
|Guardiola woke us up - Sane reveals half-time rocket for Man City|
|A first step to something bigger - Tsitsipas eyeing glory after shocking Federer|
|Thailand 1 China 2: Gao Lin keeps dream alive for Lippi|
|Tsitsipas in dreamland after ousting Federer, birthday boy Tiafoe breaks new ground|
|Huddersfield Town 0 Manchester City 3: Danilo, Sterling and Sane on target for ton-up City|
|Allegri: Khedira will be like a new signing for Juventus|
|Manchester City reach 100 goals in 2018-19|
|Australia v Uzbekistan: Leckie´s return is ´like a new signing´, says Arnold|
|Jordan 1 Vietnam 1 (aet, 2-4 on penalties): Keeper Van Lam the shoot-out hero|
|Federer confirms French Open return after Melbourne exit|
|I accept his decision - Gattuso axes Chelsea-bound Higuain|
|The rapid rise of Federer-conqueror Tsitsipas|
|Gracious Federer hails ´better player´ Tsitsipas after Australian Open exit|
|Tsitsipas ´happiest man on earth´ after stunning Federer|
|Harden focused on wins, not personal feats after scoring 48 points|
|PSG midfielder Verratti suffers sprained ankle|
|Inspired Tsitsipas dethrones Federer|
|PSG´s Cavani considering career finale in Uruguay|
|Feisty Collins ready to make more noise after thrashing Kerber|
|I´ve got to work on my soccer skills! - Mavs´ Doncic didn´t know ejection rule|
|Lakers won´t rush LeBron & Rondo back despite Ball injury|