If Borussia Monchengladbach defeat Inter later on Tuesday (, 13-time winners Madrid will not have their Group B fate in their own hands.
Shakhtar defeated Madrid in Spain on matchday one and earned another upset victory courtesy of second-half strikes from substitutes Dentinho and Manor Solomon.
Madrid are now third in the pool, behind Shakhtar due to their head-to-head record and a point behind Borussia Monchengladbach, who host Inter later on Tuesday.
Gladbach will be out of reach for the Spanish champions should they prevail against the winless Nerazzurri.
Madrid, who next face the Bundesliga side, would then have to better Shakhtar’s result against Inter on matchday six to progress.
😮 Shockhtar (again)!
— UEFA Champions League (@ChampionsLeague) December 1, 2020
Marco Asensio thought he had given Madrid a fifth-minute lead, only to see his close-range strike hit the post after good work from Karim Benzema down the left had created the opportunity.
The returning Benzema had a shot saved by home goalkeeper Anatolii Trubin, who then produced an excellent stop to deny Asensio after a slick one-two between the Spain international and Martin Odegaard.
Shakhtar lost Junior Moraes when he could not shake off an injury sustained in an incident that saw Raphael Varane booked, as the hosts failed to register a first-half shot on target.
A great move by Madrid after the break led to Benzema creating a chance for Nacho to head over.
But just as it looked like the visitors were in full control, Shakhtar threatened Thibaut Courtois for the first time when Taison surged past Varane and forced the Belgium keeper into a sharp low stop.
And the hosts took a 57th-minute lead when a pass from Viktor Kovalenko caused confusion between Ferland Mendy and Varane, allowing Dentinho to fire in a left-footed finish.
Varane did make a key block to deny Kovalenko and keep Madrid in it, while Trubin thwarted Mendy at the other end.
But another Shakhtar counter-attack settled the contest, with Solomon allowed acres of space as he carried the ball from his own half before drilling a strike beyond Courtois from 18 yards in the 82nd minute.
What does it mean? Pressure piles on Zidane
The result between Gladbach and Inter later will determine the exact permutations for the last matchday, but this upset was the last thing under-pressure Zinedine Zidane needed.
A poor start in LaLiga – including a run of just one point in their previous three matches – meant a win here, which would have secured progression with a game to spare, was a prize that offered Madrid the prospect of some breathing space.
Instead, a week of pressure, intense build-up and speculation lies ahead, with question marks for Zidane after a run of one clean sheet in 10 matches starting with the original Shakhtar defeat.
Tremendous Trubin boosts Shakhtar
Trubin made eight saves to keep a famous clean sheet, with his stop from Asensio on the half-hour mark the pick of the bunch at a time Madrid were on top.
Varane was at fault for the opening goal and Taison had breezed past him moments before it too, while the centre-back was fortunate to still be on the pitch after a couple of shaky moments following his first-half booking.
Shakhtar looked threatening whenever they got into the Madrid half after the break, while Rodrygo Goes was not much better at the other end, failing to produce a shot or key pass while losing possession a team-high 16 times in 77 minutes on the pitch.
Madrid are away to Sevilla in La Liga on Saturday (December 5), before concluding their group-stage campaign with a pivotal match at home to Gladbach next week. Shakhtar, meanwhile, host Minai at the weekend before a decisive trip to Milan to face Inter in this competition on Tuesday (December 8).
Get breaking news alerts.
You have already subscribed