Real Madrid got their Champions League title defense back up and running on Tuesday after coming through a tough battle to win 3-2 at Atalanta.
Goals from Kylian Mbappe, Vinicius Junior and Jude Bellingham were just enough for Madrid to triumph in a red-hot atmosphere in Bergamo and move up to 18th place, on nine points from six matches.
Madrid would have been at risk of dropping out of the play-off places with defeat, but came through a difficult test against the Serie A leaders, who were riding a nine-match winning streak.
Carlo Ancelotti's team moved three points from the top eight positions which give direct qualification for the last 16 with two matches remaining in their league phase campaign and the second half of this round coming up on Wednesday.
Madrid inflicted Atalanta's first defeat in this year's revamped competition and are two points behind Gian Piero Gasperini's ambitious team who performed well against the 15-time European champions but now sit ninth.
"Obviously we're a little disappointed, but we're learning so much from these matches," Gasperini told Sky.
"We're missing tiny details, but we played with heart against great champions. We were defeated in result, but not in performance."
Atalanta scored through a Charles De Ketelaere penalty in first-half stoppage time which levelled Mbappe's early opener and a fine Ademola Lookman strike in the 65th minute which put the hosts back in the match not long after Vinicius and Bellingham's quick goals.
Atalanta came within inches of snatching a dramatic draw deep in added time when substitute Mateo Retegui somehow redirected Lookman's fizzing cross over the bar from in front of goal.
Mbappe worry
It wasn't all good news for Madrid. Mbappe had to leave the field injured nine minutes before half-time, after one of his best displays since signing for the Spanish giants in the summer.
"Mbappe has some discomfort in his hamstrings. It doesn't seem serious but we'll see tomorrow," said Ancelotti.
"He couldn't sprint, it hurt him a bit and we thought it best to replace him."
Mbappe had looked in the mood from the start. He was denied by Atalanta goalkeeper Marco Carnesecchi when sent through on goal in the second minute.
Mbappe made no mistake shortly afterwards. He calmly slotted home after brilliant work by Brahim Diaz.
Mbappe skipped clear again in the 14th minute of a frantic opening only to be stopped again by Carnesecchi.
The hosts overcame the shock of going down and caused Madrid problems. Only two last-ditch clearances of Lookman crosses by Antonio Rudiger denied De Ketelaere tap-ins.
Atalanta were on top by the time Mbappe was replaced by Rodrygo. They scored the goal their first-half display deserved when Aurelien Tchouameni clipped Mario Pasalic's heels as the Croatia midfielder charged into the area. De Ketelaere rammed the resulting spot-kick past countryman Thibaut Courtois.
Atalanta pushed for the lead but were undone by bad luck in the 56th minute when an intercepted pass ricocheted off Ederson and into the path of Vinicius who marked his return from a hamstring injury by rifling in his 13th goal of the season.
Vinicius turned provider three minutes later for Bellingham who turned Marten De Roon inside out, before rolling in a brilliant finish.
That seemed to have settled the match, but Lookman rifled home his 11th goal of the season at Courtois' near post and from there the game opened up further, with both teams tearing at each other.
Lookman could not believe his eyes when his cross whipped past a sea of defenders to Retegui, who wasted a golden opportunity to level and allowed Madrid to escape with all three points.
"I don't know if we can get into top eight, but the goal is obvious, we need to win both the matches that we have left," Ancelotti told reporters.
"This win will give us a lot, it's a great win because it was based on quality play and hard work. It's given us some breathing room... Let's hope we have more players available (in January), but we're more relaxed about it after today, absolutely."