Bora-Hansgrohe's Denz launched his sprint with Israel-PremierTech's Derek Gee (25) and Alberto Bettiol (29) in hot pursuit and narrowly claimed his second stage victory after winning stage 12 this week.
Gee was second by half a wheel length, his third runners-up finish in this year's Giro, and Bettiol was third.
"I felt super good today and so I managed to get again into the breakaway," Denz said.
"I felt very good and when Bettiol launched his sprint I followed him and then I went full gas until the line. It was a very tough day but it ended well for me."
Cycling through incessant rain which required riders to wear wet weather jackets to protect them from the foul weather which has continued to disrupt this year's race, the breakaway opened up a sizeable gap of over 10 minutes.
The quartet worked together excellently to pull away from their pursuers, but ran out of steam in the final stages and were swallowed up with the finish line in sight.
Groupama–FDJ's Armirail crossed the line 53 seconds behind Denz to become the Giro's first French leader since 1999, with Geraint Thomas (36, Ineos Grenadiers) a minute and 41 seconds behind in second. Race favourite Primoz Roglic (33, Jumbo-Visma) is third.
"I wanted to look for a stage win today. I didn't really imagine that I was going to take the maglia rosa tonight. It's amazing," Armirail said.
"The moment it became a reality for me was there at the end. In the last few kilometres I was hurting, struggling, really trying to stay with everyone."
Sunday's stage 15 is a challenging 195-kilometre ride from Seregno to Bergani featuring a number of steep climbs.