Napoli were utterly dominant in a one-sided first half and took the lead on 24 minutes when Marek Hamsik put Dries Mertens through on goal as Real's defence went missing.
But captain Sergio Ramos netted one and had another header deflected in by Mertens after the break to put the holders in control.
Alvaro Morata then followed up Cristiano Ronaldo's shot to complete a comfortable victory.
Real's defensive weakness was perfectly exploited by Napoli's game plan in the first-half - a high-press put Pepe and Marcelo under pressure before Hamsik threaded a perfect through ball to Mertens who finished well in the bottom corner.
But the Italian side ultimately failed to take their other chances - Hamsik fizzed multiple shots wide before Mertens hit the woodwork and Real eventually made them pay.
The Spanish giants have now reached their seventh successive Champions League quarter-final and are unbeaten in their last 12 Champions League matches (W7, D5); their longest run without defeat in the Champions League or European Cup.
47 games in a row - but Ronaldo frustrated again
Real Madrid increased their Spanish record of scoring in 47 consecutive games with a win in Italy, but their Portuguese star striker is enduring his longest barren patch in the Champions League - Ronaldo has now gone six games without a goal.
He has five assists in seven Champions League appearances this term - his most in the competition in a single season for Real - but despite playing his part in Morata's strike, he could claim neither a goal nor an assist as he twice hit the woodwork.
Back from injury, having missed Saturday's 4-1 win over Eibar, Ronaldo had Real's best chance in the first half, but he could only hit the woodwork from a tight angle having rounded Napoli goalkeeper Pepe Reina.
Once again Real looked leaky at the back - the likes of Hamsik, Lorenzo Insigne and Mertens carving them open with relative ease during the first half.
But captain Ramos came to their rescue and Real never looked back.
The 30-year-old may be a defender by trade and have a reputation for his red card collection, but he has also made a name for himself at the other end of the pitch.
Ramos is one of only three defenders to have scored in two different European Cup finals.
Alongside Tommy Gemmell (Celtic 1967 and 70), who passed away last week, and Phil Neal (Liverpool 1977 and 84), he scored in both the 2014 and 2016 Champions League finals against Atletico Madrid.
And he came to his side's rescue once again in Naples with two emphatic headers, one deflected by Mertens, at a crucial period in the second half.
With Real Madrid completely outplayed in the first 40 minutes and a goal down courtesy of Mertens' crisp strike, Ramos rose highest from two Toni Kroos corners straight after the break to silence a 57,000-strong crowd inside the San Paolo stadium.
On a tricky night in Italy, where Real Madrid's record is somewhat shaky (18 losses, eight draws and now six wins), the Spain international stepped up when Gareth Bale, Karim Benzema and Ronaldo flew under the radar.
12 on the trot - the stats you need to know
- Real Madrid are unbeaten in the past 12 Champions League matches (W7, D5); their longest run without defeat in the Champions League or European Cup.
- Real Madrid have reached the Champions League quarter-finals in each of the last seven seasons.
- Dries Mertens has now scored 17 times in his last 16 games in all competitions for Napoli.
- Seven of Napoli's past 10 Champions League goals have either been scored (5) or assisted (2) by Dries Mertens.
- Real Madrid have progressed from each of their last nine Champions League ties in the last 16 or beyond when they've won the first leg.
- Napoli, meanwhile, have now been eliminated on each of the previous five occasions they have lost the first leg of a last 16 tie in European competition.
|Sergio Ramos has eight goals in all competitions for Real Madrid this season|
Video Highlights Read Here :
Arsenal vs Bayern Munich Highlights & Goals
SSC Napoli vs Real Madrid Highlights & Goals VIDEO
Ramos the hero as Real Madrid beat Napoli to reach quarters
Real Madrid weathered an early storm before easing through to the quarterfinals of the Champions League with a 3-1 victory over Napoli that gave them a 6-2 win on aggregate.
Trailing 3-1 from the first leg, Napoli threw everything they had at the reigning champions in an electrifying early spell, and took a deserved lead through Dries Mertens midway through the first half.
But after Cristiano Ronaldo struck a post before the break, Sergio Ramos levelled and forced a Mertens own goal in the space of six second-half minutes to turn the tie on its head, with Alvaro Morata adding a final flourish at the end.
Napoli appeared full of belief in the first half as they kept a Madrid side featuring Ronaldo, Gareth Bale and Karim Benzema on the back foot. There were early chances for Mertens, Marek Hamsik and Lorenzo Insigne before the deadlock was broken.
The goal came in the 24th minute as Hamsik's early pass picked out the run of Mertens down the left and the Belgian fired a shot low across goal and in off the post.
That only whipped up the atmosphere at the Stadio San Paolo further but Madrid were quick to counter, going close to levelling the scores when Ronaldo's run split the defence and he sent a shot against the post in the 29th minute.
Napoli appeared to heed the warning as they reasserted control, with Kalidou Koulibaly heading over and Mertens striking a shot against the outside of the post.
The hosts emerged for the second half full of running once more, but the momentum shifted in the 51st minute when Madrid counter-attacked swiftly and won a corner from which Ramos headed them level.
Napoli had barely had chance to recover before Madrid took the lead, again from a corner. Once more Toni Kroos was the provider, picking out Ramos whose header found the net via a deflection off Mertens.
That proved pretty much conclusive as Napoli struggled to regroup and reassert themselves in the match.
Dani Carvajal had a golden chance to add to Madrid's margin of victory as the match moved into the final 10 minutes, but spooned the ball horribly over with the goal gaping.
Instead Morata would have the final word as he rifled home Madrid's third of the night and sixth of the tie in stoppage time after Jose Reina failed to hold Ronaldo's shot, palming it straight into Morata's path.
The central defender was once more Madrid's matchwinner at San Paolo as he headed home twice to overturn Dries Mertens' early goal
Sergio Ramos once again rose to the occasion as the centre-back's double saw Real Madrid come from behind to win 3-1 at Napoli and secure progression to the Champions League quarter-finals with a 6-2 aggregate triumph.
The Spain international has come up with the goods on the big stage for Madrid time and time again, including in last season's Champions League final, and he allayed Madrid's fears with two goals in quick succession after the break to turn things around following Dries Mertens' well-taken first-half opener.
The match lived up to its billing in the opening 45 minutes, as Napoli took the game to the reigning European champions and caused them no end of problems from the start, before eventually halving Madrid's two-goal aggregate lead just before the half-hour mark – Mertens scoring his 17th goal in his last 16 games across all competitions.
Both sides were then denied by the frame of the goal, as Cristiano Ronaldo's Champions League goal drought was extended to six matches, while Mertens went close to scoring his second.
But Napoli were made to rue their plethora of spurned first-half chances, as Ramos swiftly restored Madrid's two-goal advantage early in the second half, before then scoring again to take his respective tally for the entire season to 10.
That quick brace left the hosts completely deflated and Alvaro Morata made the scoreline more flattering in stoppage time.
Napoli lived up to Madrid boss Zinedine Zidane's expectations with a purposeful start and carved Madrid open early on, but Marek Hamsik was a whisker away from meeting Lorenzo Insigne's cut-back 12 yards out.
Hamsik did manage to get a shot away a few moments later, though his attempt from the edge of the box went agonisingly wide of the right-hand post.
The hosts' dominance showed no sign of letting up and they eventually broke the deadlock 24 minutes in.
Madrid were dissected by a series of passes and Hamsik fed Mertens into the left side of the box, with the Belgian then coolly slotting into the bottom-right corner.
Ronaldo provided a reminder of his presence shortly after, but his effort came back off the right-hand post after he breezed into the area and skipped past Pepe Reina.
Napoli too were kept out by the post just before the interval – Mertens the one denied after the ball broke kindly for him in the area.
Madrid began the second half with much greater control and intent, and they hauled themselves level on the night within five minutes of the restart – Ramos meeting Toni Kroos' left-wing corner with a glancing header that found the bottom-right corner.