The visitors took the lead after Keylor Navas was caught off guard by a superb Lorenzo Insigne strike inside eight minutes.
Karim Benzema headed the equaliser past Pepe Reina from Dani Carvajal's cross 11 minutes later.
Toni Kroos put the hosts ahead early in the second half, before a stunning volley from Casemiro sealed the win.
Napoli will host the second leg on 7 March, with a place in the quarter-finals at stake.
Cristiano Ronaldo has now gone 523 minutes without a Champions League goal - his longest drought in the competition at Real Madrid.
The 32-year-old missed a golden opportunity midway through the first half to give Real a 2-1 lead, but he blasted his shot over the bar from 12 yards out.
Ronaldo's performance was far from selfish and he was lively from the off. He created a chance after just 23 seconds with his darting run finding Benzema, who forced a one-handed save from Reina.
Although Ronaldo failed to hit the target during the game, his hard work paid off when he pulled the ball back to Kroos to give the hosts the lead early in the second half.
That makes it five assists in seven Champions League appearances this season - his most in a season in the competition for Real Madrid.
Insigne set the standard with his impressive early goal. Marek Hamsik ripped apart the Real defence with the through ball and Insigne made no mistake in converting.
He spotted Navas off his line and curled the opener into the bottom corner from 35 yards out with Napoli's only shot on target in the first half.
But Casemiro stole his thunder with a world-class finish to wrap up the win for Real, leaving Reina with no chance with a long-range volley.
The Brazilian has had 16 attempts in the Champions League, scoring only twice with both goals coming from outside the box.
Carvajal delivered a sumptuous cross with the outside of his boot to tee up Benzema for the equaliser and his 51st goal in Europe.
His powerful header sees him move up to fifth in the competition's all-time leading scorers, overtaking Thierry Henry.
Ronaldo tops the list with 95 goals, followed by Lionel Messi (93), Raul (71) and Ruud van Nistelrooy (56). - BBC -