Peters, riding for the Ag2r-La Mondiale team, blew away his rivals at the end of the 181km run through the north of Italy, near the Austrian border.
The 25-year-old pulled clear 16km from the line and had built up an advantage of one minute at the foot of the 5.5km final climb.
"It's enormous! I'd never won, I'd always come close," said the rider from the mountainous region of Isere in south-eastern France.
Colombian Esteban Chaves, riding for Mitchelton-Scott, finished a distant second 1min 30sec behind with Italy's Davide Formolo of Bora-Hansgrohe third at 1min 51sec.
"It's incredible to get my first pro win in a Grand Tour," continued Peters.
"My Giro was already a success having worn the top young rider's white jersey for a few days. I had no stress."
Peters had already been among the leaders in the sixth stage, but had been unable to finish off and dropped to eighth.
But it allowed him to pull on the white jersey for three days.
Movistar rider Carapaz kept the overall leader's pink jersey, extending his lead over Italy's Vincenzo Nibali (Bahrain-Merida) and Primoz Roglic (Jumbo-Visma) by seven seconds.
Britain's Simon Yates, the Vuelta a Espana champion, remains eighth, 7min 13sec behind the race leader.
A group of 18 riders had formed a breakaway in an animated start after Tuesday's wet and cold conditions at Mortirolo.
"I focused on Formolo and (Thomas) De Gendt who were the strong men of the breakaway," explained Peters.
"I saw that the others were biding their time and I went for it without questioning myself."
Carapaz put his foot down on the pedal over the final kilometre, gaining seven seconds on Nibali, who he leads by 1min 54sec.
Movistar rider Mikel Landa of Spain also attacked and is now less than a minute behind third-placed Roglic in fourth.
"Mikel Landa felt good in the finale and decided to attack to gain some time for the final podium," said Carapaz.
"I also felt good and I did my best to profit from Mikel's attack. I couldn't have asked for a better 26th birthday than with the Maglia Rosa (pink jersey)."
Thursday's stage offers the remaining sprinters a final chance for a win as the route drops to sea level, with a 222km run through the Venetian hinterlands from Valdaora to Santa Maria di Sala, concluding with a 2km sprint for the line.
The race concludes in Verona on Sunday.
Results after Wednesday's 17th stage of the Giro d'Italia over 181km from Commezzadura to Antholz:
1. Nans Peters (FRA/AG2R La Mondiale) 4hr 41min 34sec, 2. Esteban Chaves (COL/MIT) at 1min 34sec, 3. Davide Formolo (ITA/BOR) 1:51, 4. Fausto Masnada (ITA/AND) 1:51, 5. Krists Neilands (LAT/ICA) 1:51, 6. Tanel Kangert (EST/EF1) 2:02, 7. Valerio Conti (ITA/UAE) 2:08, 8. Gianluca Brambilla (ITA/TRE) 2:08, 9. Chris Hamilton (AUS/SUN) 2:22, 10. Andrea Vendrame (ITA/AND) 2:34
19. Mikel Landa (ESP/MOV) 4:27, 20. Richard Carapaz (ECU/MOV) 4:39, 21. Miguel Angel Lopez (COL/AST) 4:39, 25. Primoz Roglic (SLO/JUM) 4:46, 26. Vincenzo Nibali (ITA/BAH) 4:46, 29. Simon Yates (GBR) 5:06
1. Richard Carapaz (ECU/Movistar) 74hr 48min 18sec, 2. Vincenzo Nibali (ITA/BAH) at 1min 54sec, 3. Primoz Roglic (SLO/JUM) 2:16, 4. Mikel Landa (ESP/MOV) 3:03, 5. Bauke Mollema (NED/TRE) 5:07, 6. Miguel Angel Lopez (COL/AST) 6:17, 7. Rafal Majka (POL/BOR) 6:48, 8. Simon Yates (GBR/MIT) 7:13, 9. Pavel Sivakov (RUS/INE) 8:21, 10. Davide Formolo (ITA/BOR) 8:59
17. Giulio Ciccone (ITA/TRE) 25:17, 23. Eddie Dunbar (IRL/INE) 37:20, 24. Damiano Caruso (ITA/BAH) 44:03, 29. Bob Jungels (LUX/DEC) 50:14, 56. Nans Peters (FRA/ALM) 1hr 40:25, 57. Thomas De Gendt (BEL/LOT) 1hr 41:36