Kiev - Spanish giants Real Madrid survived a nervous finish when they conceded three late goals to edge Shakhtar Donetsk 4-3 and wrap up top spot in Champions League Group A.
Cristiano Ronaldo scored twice while Luka Modric and Dani Carvajal were also on target for Real who had already made sure of their place in the last 16 before Wednesday's match at the Lviv Arena.
But just four days after suffering a 4-0 mauling at the hands of Barcelona in El Clasico, there were still worrying signs of Real's defensive frailities for under-pressure coach Rafael Benitez.
They were cruising at 4-0 on Wednesday before Shakhtar hit three goals in the last 12 minutes with stand-in skipper Alex Teixeira scoring twice and fellow Brazilian Dentinho also on target.
In the night's other Group A encounter, French champions Paris Saint-Germain thrashed Malmo 5-0 to join Real in the knockout round.
Shakhtar, weakened by the absence of regular captain Dario Srna and full-back Alexander Kucher, who were both suspended, needed to win to have any chance of creeping into the last 16.
But Real were quickly into their stride. In the second minute, Modric found the unmarked Ronaldo in the area but the Portuguese star fired over the crossbar.
Ronaldo made amends just 16 minutes later when he scored with a close-range header from a fine cross by Gareth Bale.
Real goalkeeper Kiko Casilla was rarely troubled while Ronaldo missed a clear chance to double his team's lead in the 30th minute.
In the 50th minute, Ronaldo turned provider when he slipped away from the Shakhtar defence on a breakaway before Croatian international Mordic fired home from just outside the six-yard box.
Carvajal made it 3-0 for Real two minutes later, lobbing the ball into the net over goalkeeper Andriy Pyatov from the edge of the penalty area.
Ronaldo scored his second - and Real's fourth - in the 70th minute when he was quickest to react after Yaroslav Rakitskiy had blocked his initial close-range shot.
Real went suddenly off the boil with Teixeira pulling a goal back from the penalty spot in the 78th minute after Casemiro brought down Taison in the area.
Dentinho scored Shakhtar's second five minutes later before Teixeira cut the deficit even further in the 88th minute.