Wednesday's Group B clash seemed to be set up for a straightforward Madrid win, with Shakhtar clear underdogs even before losing half their squad to COVID-19 in a situation coach Luis Castro described as "a nightmare".
But Zinedine Zidane's LaLiga champions were outthought and outfought for 45 minutes at their temporary Estadio Alfredo Di Stefano home as strikes from Mateus Tete and Manor Solomon sandwiched a Raphael Varane own goal to secure a three-goal half-time lead.
Madrid also lost at home to Cadiz last Saturday and visit bitter rivals Barcelona in the Clasico this weekend yet at least showed some fight after the break.
Efforts from Luka Modric and Vinicius Junior set up a grandstand finish, but Federico Valverde's apparent equaliser in stoppage time was disallowed for offside as Shakhtar survived for a sensational victory.
The Ukrainian outfit should have led even before they did as Marlos ran clear and had time to pick his spot but sent an awkward effort into Thibaut Courtois' legs.
It was not a miss the makeshift visiting side were made to pay for, though, as they repeatedly dismantled a dismal Madrid defence, Tete sliding in an assured finish for the first before having a hand in the next two.
Courtois spilled Tete's shot at the feet of Dentinho, prompting Varane into a desperate lunge that succeeded only in turning the ball past his own goalkeeper, and the winger's cute backheel then teed up Solomon to make it three.
Madrid were much improved following the restart but still scarcely threatened until Modric's sublime strike, finding the top-right corner from 25 yards.
That flicker of hope should have been swiftly extinguished by Tete, yet the star of the first half somehow blasted wide after running onto Viktor Korniienko's cutback.
By contrast, Vinicius was clinical at the other end, emerging from the bench to score with his first touch as he stole possession from Marlos and swept into the net.
Tete squandered another opportunity, shooting straight at Courtois, and was then just offside before squaring for Marlos to net what Shakhtar thought was a clincher.
Valverde's deflected 92nd-minute attempt squirmed past Anatolii Trubin to seemingly deny Castro's men, but Vinicius - stood in front of the keeper - was offside and Madrid were beaten.
What does it mean? Crisis looming ahead of Clasico
Well, that did not take long. Madrid were crowned LaLiga champions just three months ago and are already facing a potentially make-or-break fixture on Saturday when they make the trip to Camp Nou.
If Zidane's men play again as they did in the opening 45 minutes here, when they gave up four shots, all on target and all from inside the box, they are unlikely to find Lionel Messi in forgiving mood.
Tete takes centre stage
Starting wide on the right, Tete's ability to drift inside and combine with team-mates caused Madrid all sorts of problems. His only key pass was the gorgeous assist for the third, but he was involved in almost every away move.
Second-half wastefulness threatened to undo his hard work, yet Tete also defended from the front, making two tackles and an interception, as well as contesting 20 duels.
Misery for Madrid's Marcelo
A series of right-back injuries have seen Ferland Mendy moved across from the left-hand side of the defence, meaning Marcelo must start. But this was a punishing experience for the veteran.
Marcelo was dragged out of position for goals one and three, the victim of much of Tete's best work, although he did make three tackles and timed a late offside trap to deny his opponent on the counter.
Key Opta Facts
- Real Madrid have lost three consecutive matches in the European Cup/Champions League for the first time since September 1986.
- Shakhtar Donetsk are the first Ukrainian side to win against Madrid in the Champions League since Dynamo Kiev's 2-0 victory in March 1999. Neither of Shakhtar's two scorers - Tete and Solomon - were born then.
- Madrid shipped three first half goals in a Champions League game for the first time since September 2005 against Lyon, and the first time in a home game since February 2000 against Bayern Munich.
- Vinicius scored for Madrid just 15 seconds after coming on as a substitute – this is the fastest such goal in the Champions League since 2006-07 (when Opta first collected this data).
- Madrid have lost seven of their past eight Champions League matches that have not featured Sergio Ramos.
Madrid simply must respond against Barca in a bid to get their season back on track. Shakhtar, third in their domestic league, go to second-placed Vorksla earlier on Saturday.