Dani Ceballos’ 89th-minute goal ensured Real Madrid finished their Champions League group stage with a perfect record after they beat Union Berlin 3-2.
Ceballos’ deflected strike settled a topsy-turvy battle in the German capital, with Union heading out of Europe for the season.
They had taken the lead in the first half through Kevin Volland’s opener, but Joselu scored twice in 11 second-half minutes to put Real in front.
Alex Kral levelled for the hosts in the 85th minute as Union looked set for a point before former Arsenal loanee Ceballos won it for the 14-time champions.
It might have been a more serene night for Carlos Ancelotti’s side had they taken some early chances, with Jude Bellingham going close from distance and Joselu missing a good chance that he should have put away.
A golden chance came their way just before half-time when Diogo Leite made a rash challenge in the box and the referee pointed to the spot.
Luka Modric stepped up and he went down the middle, but Union goalkeeper Frederik Ronnow was waiting and saved.
It kicked off a dramatic two minutes as the hosts went down the other end and when David Alaba missed his kick, Volland stormed through and converted.
Real were in control in the second half and Ronnow made another fine save as he kept out Rodrygo’s header from close range.
But there was nothing the Danish goalkeeper could do to prevent the leveller in the 61st minute as Joselu nodded in Rodrygo’s cross.
It was a clinical finish by Joselu which gave the visitors the lead 11 minutes later as he superbly turned in Fran Garcia’s cross at the near post.
Kral looked to have earned Berlin an unlikely point when he slammed home from the edge of the area as the hosts suddenly had hopes of finding another goal that would have sent them through to the Europa League.
However, Ceballos broke their hearts in the 89th minute when his deflected effort nestled in the bottom corner as Real Madrid ended with a perfect record.