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.
|Fan shows off Monk face tattoo on bottom|
|Bayern Munich chief Hoeness rules out spending spree|
|Fury to take on Albanian Seferi in Manchester next month|
|Mourinho mind games won´t distract from Manchester United´s paused progress|
|My motivation is intact - Ranieri open to offers following Nantes exit|
|Shields would probably have made All Blacks squad - Hansen|
|Willian fuels rift talk by hiding Conte with emojis in cup photo|
|Marquez extends lead at Le Mans as Dovizioso crashes again|
|Top-six mentality a boost to England´s World Cup hopes – Southgate|
|Dominant Svitolina retains in Rome as Halep sustains injury scare|
|I´d play for free! - Fifita desperate for State of Origin call-up|
|Plea satisfied with Nice exit as big changes beckon|
|Boateng open to leaving Bayern for move abroad|
|Napoli slam ´shameful and offensive´ Juventus celebrations|
|Red Star´s open-top bus goes up in flames|
|Klopp rejects Liverpool´s Champions League final underdogs tag|
|Root trusts batting form to ´click´ for England|
|Matic wants Man Utd to back Mourinho in transfer market|
|Walker out with eye socket fracture following Melbourne-Manly brawl|
|Don´t try it at home! - LeBron wows with game three passing|
|Dragons restore two-point lead, Sharks battle past Bulldogs|
|Any club would want Buffon, says PSG president|
|Villarreal renew Calleja contract after Europa League qualification|
|Talisca heading to Premier League, hints Besiktas boss|
|Celtics ´needed to get our butts whooped´ by Cavs, says Rozier|
|Bayern should have had a penalty, admits Boateng|
|NBA great Bill Russell released from hospital|
|When I play I´m Luca, not Zidane – Zinedine´s son distances himself from father|
|Barzagli: Buffon the greatest of all time|
|Indians ace Kluber becomes first in AL to seven wins|
|MLS Review: Two-goal Villa inspires NYC rout, Timbers stay hot|
|Kuznetsov sets Capitals´ playoff points record|
|Stevenson-Jack showdown ends in majority draw|
|Galatasaray win 21st Turkish title on final day|
|Cavaliers rout Celtics to cut series deficit to 2-1|
|Harvick holds off Suarez to win All-Star race and $1m|
|All Blacks name three new faces for France Tests|
|Mo Salah 15 years behind Cristiano Ronaldo – Klopp|
|Jaguares extend winning streak with Bulls thrashing|
|Nobody is bigger than PSG, says Al-Khelaifi amid doubts over Neymar|
|Warrington targets Frampton after Selby upset|
|Zidane says Real Madrid are ready for Champions League final|
|Heynckes: Bayern aren´t bad losers after DFB-Pokal snub|
|Everything was positive - Emery leaves PSG satisfied|
|Wise, Leishman tied for Byron Nelson lead|
|Torres, Iniesta share gift of good decisions - Simeone|
|Arrivederci Buffon - The Juventus´ greats remarkable career in numbers|
|Favre leaves Nice as Dortmund post awaits|
|´Extraordinary´ Juventus deserved Serie A title - Allegri|
|Warrington upsets bloodied Selby to secure world title|
|Sweden batter USA, Swiss roll on to gold medal match|
|Zverev battles past Cilic to extend winning streak|
|It was a penalty - Kovac acknowledges Frankfurt´s good fortune ahead of Bayern move|
|Ligue 1: Depay fires Lyon into Champions League as Troyes go down|
|Tigers tear Rhinos to shreds as Saints stay clear at the summit|
|Mourinho criticises Chelsea long-ball tactics in FA Cup final|
|Caen 0 Paris Saint-Germain 0: Stalemate closes Emery tenure as Caen survive|
|Villarreal 2 Real Madrid 2: Luca´s debut misjudgement costs Los Blancos|
|Conte reaffirms Chelsea commitment and hints at Italy offer|
|Leicester agree €20m deal for Porto´s Pereira|
|Bayern Munich 1 Eintracht Frankfurt 3: Controversial Kovac win denies new club double delight|
|I am a serial winner, Conte declares after Chelsea´s FA Cup glory|
|Courtois delighted to dispel doubts with FA Cup triumph|
|FA Cup win was to save Chelsea season - Cahill|
|Brilliant Hazard ensures Conte´s serial-winner status remains intact|
|Knight Riders cruise into the IPL play-offs|
|Mourinho: I can imagine what people would say if my team played like Chelsea|
|Mourinho: Lukaku chose not to start FA Cup final|
|Hazard shies away from future talk after Chelsea´s FA Cup success|
|Today is your moment - Juventus legend Del Piero pays tribute to Buffon|