Demare (Groupama-FDJ was too quick on the 150 km route from San Remo to Cueno, pipping Phil Bauhaus (Bahrain Victorious) and Mark Cavendish (Quick-Step Alpha Vinyl) to the line and claiming his third stage victory of this year’s race.
Spaniard Juan Pedro Lopez retained his 12-second overall lead to hold on to the pink jersey.
Ecuador's Richard Carapaz remained in second overall, ahead of Portugal's Joao Almeida with both riders tied for time.
Australian Jai Hindley (Bora-Hansgrohe) moved up to fourth, 20 seconds behind the leader, after Frenchman Romain Bardet (DSM) pulled out due to illness.
The stage unfolded at a blistering pace with an average speed of 45.393 kph, making this the first time in the history of the Giro that three consecutive stages had an average speed of at least 45 kph.
With 140km remaining five riders launched a successful breakaway with four remaining clear - until they were reeled in with one kilometre remaining.
Groupama-FDJ's riders then got Demare into position to claim victory and he duly obliged.
"At some point I started to doubt that we'd be able to catch the breakaway because some elements of my team had given everything they had," Demare, who secured his eighth career Giro win, said.
"They were very committed. I've also had the feeling that I was cooked myself.
"With 10 km to go, I've started to believe it would be a sprint finish. I was at the limit for sprinting. It's exceptional to get one more win. Three is a lot."
Saturday's stage 14 is a challenging 147km ride from Santena to Torino, which begins with a short flat section before a series of climbs.
The Giro d'Italia continues on SBS with Stage 13, with some hard climbing until the mid-point of the stage, with a relatively plateau-like run to the finish from there. Watch from 9.10pm AEST on SBS On Demand, with the SBS broadcast starting from 11pm. WA viewers can watch from 9pm AWST on SBS VICELAND.