Substitute Danilo scored a debut goal for Juventus just 26 seconds after replacing the injured Mattia De Sciglio. The Brazilian slotted home after a fine run and cross by Douglas Costa after 16 minutes.
Juventus doubled their lead on 29 minutes through former Napoli striker Gonzalo Higuain. The Argentine turned past Kalidou Koulibaly in the penalty area and then lashed a fierce effort past Alex Meret.
Ronaldo added a third on 62 minutes that looked to have secured the win. However, two goals in four minutes from Kostas Manolas and Hirving Lozano offered the visitors hope.
The equaliser arrived with nine minutes of normal time remaining. Piotr Zielinski lofted a ball forward for Giovanni Di Lorenzo to make it 3-3 and cap a fine comeback.
However, there was still time for more drama at the Juventus Stadium, with the hosts securing the win in stoppage time. Koulibaly attempted to clear Miralem Pjanic's ball into the box but succeeded only in slicing the ball past his own goalkeeper and into the top corner.
Juventus suffered an early blow when De Sciglio was forced off with a muscular problem, per Football Italia.
Danilo replaced the 26-year-old and made an immediate impression on his debut. A quick break saw Costa race down the left flank and square the ball for Danilo to force home, as shown by Premier Sports (UK only):
The host then took control of the game after some superb play by Higuain. The striker produced a great turn to beat Koulibaly and then hammered a strike past Meret:
Juventus had further chances to extend their lead before half-time. Sami Khedira was denied by Meret after more good work from Higuain and then hit the crossbar with a shot from the edge of the box.
Ronaldo looked to have wrapped things up in the second half. The Portugal international swept home Costa's cross on 63 minutes to open his account for the new season.
ESPN's Matteo Bonetti was impressed with Juve's display:
However, Napoli produced a superb response and pulled a goal back four minutes later. Mario Rui floated a free-kick into the box for an unmarked Manolas to head home.
Substitute Lozano then reduced the deficit further with a debut goal for Napoli. The Mexican side-footed Zielinski's cross home to make it 3-2.
Napoli's equaliser came from another set piece that Juventus failed to deal with. Again, Zielinski produced a precise delivery for Di Lorenzo to convert with his thigh.
Juventus summer signing Matthijs de Ligt came in for criticism for his part in the goals:
Di Lorenzo's strike looked to have earned Napoli a memorable comeback, but the visitors suffered heartbreak in stoppage time.
Pjanic's hopeful free-kick into the box from deep was met by Koulibaly, and the defender could only slice the ball into the top corner to hand Juventus all three points.