Goals from Karim Benzema, Toni Kroos and Casemiro gave the title holders an important advantage to take back to Italy after Lorenzo Insigne's sensational opening goal had put Napoli ahead.
Zinedine Zidane had urged his side to keep a clean sheet to give them the best possible chance of going through, but those hopes were dashed after only eight minutes when Insigne embarrassed goalkeeper Keylor Navas with a stunning first-time effort from distance.
Benzema had missed a clear chance inside the first minute but he made amends by levelling the scores with his 51st goal in the competition - one more than the previous best tally for a French player, set by Thierry Henry.
Diego Maradona had given Napoli a pre-match team talk in a bid to instill belief of achieving an upset, but Kroos' clever finish from a Cristiano Ronaldo cross and a thunderbolt from Casemiro effectively killed off those hopes early in the second half.
Dries Mertens - who has scored 13 goals in nine Serie A games in a devastating run of form - missed a clear opportunity to halve the deficit, although Pepe Reina had to make a smart stop to prevent surprise starter James Rodriguez from scoring a fourth.
Madrid survived some late Napoli pressure to hold on to their two-goal advantage, but Maurizio Sarri's side - who saw an 18-match unbeaten run come to an end - will not be without hope in the second leg at the San Paolo.
Madrid showed their attacking intent inside the first minute, Benzema stinging the right hand of Reina after he had been teed up by Ronaldo.
The home side bossed possession early on but they were stunned by a piece of brilliance from Insigne on the break with only eight minutes on the clock.
The Italy forward raced through onto Marek Hamsik's pass and, 35 yards from goal, he curled a first-time strike past the despairing dive of the out-of-position Navas and into the right-hand corner.
Napoli were looking confident and composed but they relaxed a little too much to allow Benzema to equalise 11 minutes later, the striker glancing a header into the net from six yards after Dani Carvajal was allowed time and space to the right of the area to produce a sublime outside-of-the-foot cross.
The frantic pace of the early exchanges began to lull but Benzema should have scored a second three minutes before the interval, though he could only steer a low effort onto the post after a fine break involving Carvajal and Ronaldo.
Four minutes after the restart, however, Madrid took the lead for the first time in the tie. Ronaldo skipped his way brilliantly beyond Kalidou Koulibaly and into the area from the right, and his measured pass back to the edge of the area was promptly swept into Reina's bottom-left corner by the arriving Kroos.
Madrid sensed the chance to go for the kill and they added a third just five minutes later in spectacular - and unlikely - fashion. The ball was prodded away from James on the edge of the area as far as Casemiro, and the Brazilian blasted a dipping right-foot volley beyond the helpless Reina and into the bottom-left corner.
Mertens had been kept on the fringes of the action but he wasted a great chance to give Napoli a second away goal, curling a shot over the bar with the goal gaping after Jose Callejon controlled the ball into his path, and James would have punished that miss had Reina not raced off his line to make a good block at the Colombia star's feet.
Madrid dropped deeper in a bid to soak up some late Napoli pressure and, with the exception of a Callejon goal that was correctly ruled out for offside, they held firm to secure what could prove to be an insurmountable lead.