Substitute Karim Benzema headed a late winner as holders Real Madrid secured their place in the knockout stages of the Champions League with a 2-1 victory over 10-man Sporting Lisbon at Estadio Jose Alvalade.
A draw would have been enough to send the in-form LaLiga leaders through from Group F alongside Borussia Dortmund.
It appeared Zinedine Zidane's side would be left with just that after a penalty from Adrien Silva after 81 minutes had cancelled out Raphael Varane's first-half opener, with the home side having seen defender Joao Pereira sent off after appearing to punch Mateo Kovacic.
However, with just three minutes left, Benzema nodded in a weighted cross from Sergio Ramos to secure victory and set up a Madrid showdown with Dortmund for top spot next month.
One negative for Los Blancos, though, was the loss of Gareth Bale to what looked like an ankle injury just before the hour.
Real coach Zidane earlier made just one change to the side which beat city rivals Atletico 3-0 at the weekend, with Ramos coming back into the centre of defence.
All of the pre-match talk had been of Ronaldo returning to his former club.
The Portugal star had an early chance with a low shot on the turn, which Sporting keeper Rui Patricio got down to save comfortably.
Real threatened again after 15 minutes when Bale rolled the ball across the face of goal, which Sebastian Coates knocked behind before Ronaldo could put it away.
Sporting, who were battling against the odds to keep their own slim qualification hopes alive, created an opening when Gelson Martins' ball in almost found Bas Dost as the Dutchman slid in at the far post.
Los Blancos, though, swept into the lead after 29 minutes.
A low free-kick from the right by Luka Modric dropped through a crowded penalty area, with Ronaldo knocking the ball into the six-yard box where French defender Varane, who was played onside by a static Porto backline, swept it in from close range.
Sporting came close to a swift equaliser following a break down the right when Bruno Cesar's goalbound effort was cleared behind by a diving header from Ramos.
Just before half-time Cesar's curling effort was just wide as Real keeper Keylor Navas scrambled across his goal.
In the 58th minute, having earlier needing treatment on what looked like an ankle problem, Bale was replaced by Marco Asensio.
Sporting were reduced to 10 men in the 64th minute following the dismissal of Pereira when the defender appeared to punch Kovacic in the stomach as the duo squared up on the far touchline, leaving Scottish referee Willie Collum little option but to show a red card.
The Portuguese side, though, were gifted a way back into the match with 11 minutes left.
Real substitute Fabio Coentrao was punished for a handball just inside the box, the defender appearing to still be appealing for the same offence against Joel Campbell, and Silva made no mistake from the penalty spot.
Sporting suddenly had found new life and pressed for a winner, as Campbell, on loan from Arsenal, sent a header over at the far post.
But it was Real who made sure of all three points after 87 minutes when substitute Benzema nodded in.