The 24-year-old crossed the finish line in a time of 5:11:35, with Bora-Hansgrohe’s Davide Formolo in second and Groupama-FDJ’s Thibaut Pinot third.
Riders had to tackle a 209km course that kicked off in Praia a Mare, where yesterday’s stage ended, and featured a summit finish.
The final climb, which started with 17 kilometres to go, featured an average gradient of 6% with a maximum of 10. It was a steady climb with no seriously steep sections.
When the leaders reached the climb they had a gap of two minutes and 27 seconds over the peloton.
With 10 kilometres left, LottoNL-Jumbo’s Koen Bouwman had created a gap and was soon joined by AG2R La Mondiale’s Matteo Montaguti, Bahrain-Merida’s Matej Mohoric and UAE Team Emirates’ Jan Polanc. At this stage the gap was one minute and 12 seconds.
The gap came down to 50 seconds with seven kilometres left.
Team Sky’s Chris Froome caused a crash in the peloton when he slipped out on a corner, but was soon back up at the front of the group. This was his second crash in the first week of racing.
With a 20-second gap to the peloton, Montaguti tried to chase Bouwman down as Mohoric and Polanc were brought back.
Bouwman had a 14-second gap with just over one kilometre left as Montaguti was caught by the peloton.
His lead did not last long as Carapaz, who is the current best young rider, executed an attack and passed Bouwman.
The Ecuadorian cyclist, who won the Vuelta a Asturias earlier this year, continued climbing well and eventually crossed the finish line to claim his first Grand Tour win.
“I’m very happy, I have worked a lot before the Giro. Of course having the first Grand Tour win – it’s emotional,” said Carapaz.
“I had good legs, so I decided to attack from far out. I decided it was the right time to go alone, because I knew I couldn’t win in a sprint.”
Carapaz said he would take it day by day as there was still a long way to go to Rome.
“I’m here to see what I can do at the Giro.”