Sporting took the lead through a low shot from Bruno Cesar but Cristiano Ronaldo equalised in the 89th minute with a superb long-range free-kick.
And Alvaro Morata – back at Real after two years with Juventus – won it with a stoppage-time header.
Elsewhere Borussia Dortmund won 6-0 and Juventus were held to a 0-0 draw.
Ronaldo finally finds a free-kick
Ronaldo’s free-kick was just about unstoppable
Ronaldo extended his record of failing to score in 43 free-kick attempts at major tournaments for Portugal this summer as they won Euro 2016, but was back on target as he smashed in off the post from 25 yards.
It was his 12th career free-kick in the Champions League and took his total to 94 goals in the competition – and 79 in 76 games for Real.
Ronaldo has now scored on each of the five occasions he has played his previous clubs in the Champions League.
He scored home and away against Sporting for Manchester United in 2007, and scored in both legs of the 2013 quarter-final for Real against United.
“No side will play here in Madrid as well as we have done,” said Sporting boss Jorge Jesus.
“Real didn’t have a single chance in the first half, but there’s a reason they’re European champions. They have that mentality and reputation and changed the game in two minutes.”
Dortmund off to a flyer
Legia Warsaw can expect a fine from Uefa after this colourful welcome from fans bearing flares
Borussia Dortmund thrashed Legia Warsaw 6-0 in the Polish capital with goals from Mario Gotze, Sokratis Papastathopoulos, Marc Bartra, Raphael Guerreiro, Gonzalo Castro and Pierre-Emerick Aubameyang.