Gaviria (Quick-Step Floors) edged Italian rival Jakub Mareczko (Wilier Triestina-Selle Italia) at the end of the 229km route from Forli to Reggio Emilia. Sam Bennett (BORA-hansgrohe) was third in the 12th stage.
Overall, Tom Dumoulin (Sunweb) remained 2min, 23sec ahead of 2014 winner Nairo Quintana (Movistar) and 2min 38sec ahead of Bauke Mollema (Trek-Livestrong).
The 22-year-old Gaviria is the first rider to win three stages on his Grand Tour debut since Uwe Raab in 1990, but he brushed off claims he is the best sprinter in the peloton.
"I'm not the best sprinter of this Giro," Gaviria said. "That's Andre Greipel because he's got many more wins in his career than me but right now, I'm the sprinter with the best form and the best legs thanks to the preparation. And that's how I'm here with my third victory."
Dumoulin's overall lead was never really under threat, crossing the line with the rest of the GC contenders, six seconds behind Gaviria.
"Today was a pretty relaxed stage so it was a good day," he said. "There was a tailwind in the final which made it really fast, but the team had positioned me well to stay out of any trouble.
"Tomorrow is another sprint day so we aim to keep safe again and look forward to the mountain stages coming up at the weekend."
Mirco Maestri (Bardiani–CSF) had been hoping for a first stage win, in his hometown, and he was part of the early break along with Sergey Firsanov Gazprom–RusVelo) and Marco Marcato (UAE Team Emirates).
The trio had an advantage of nearly seven minutes at one point but Quick-Step Floors upped the pace as the finish approached and the peloton reeled them in.
Firsanov and Marcato were caught with 11km remaining and Maestri was also swallowed up five kilometres further down the road.
Friday's 13th stage is another one for the sprinters, a completely flat 167km route from Reggio Emilia to Tortona.