The last few kilometres of the fifth stage saw a flurry of attacks from the front bunch, however, at the end of the day it came down to a mass sprint.
Ackermann launched an attack in the final metres, which resulted in Gaviria moving to the front, but Ackermann brought it back and took the victory.
“I think this was a two-time sprint for me today because I had to brake in the final 200m but then luckily Gaviria was the perfect lead-out for me and I had a lot of power in the end and I’m just happy about today,” said Ackermann, who also won this year’s Eschborn-Frankfurt, Clásica de Almería and Bredene–Koksijde Classic.
“The sprint was really scary, the stage was really scary. On the descents you couldn’t see much because of the water and it was lucky nobody crashed.”
Shortly after Tom Dumoulin decided to abandon the race during the neutralised section, Louis Vervaeke (Team Sunweb), Umberto Orsini (Bardiani-CSF), Enrico Barbin (Bardiani-CSF), Ivan Santaromita (Nippo Vini Fantini-Faizane) and Miguel Florez (Androni Giocattoli-Sidermec) were in a breakaway and had a maximum lead of two minutes.
Vervaeke broke away with 53km remaining and led the race solo, while the quartet was caught by the peloton.
Vervaeke’s maximum gap was 1:20 before he was caught by the peloton with 23km to go, which stayed together until the last couple of kilometres.
A call was made for the general classification times to be taken on the first passage of the finish line with 9km to go, due to the wet conditions.
Primoz Roglic (Team Jumbo-Visma) still managed to hold on to the pink jersey, with Simon Yates (Mitchelton-Scott) second and Vincenzo Nibali (Bahrain-Merida) third.
The sixth stage will cover 238km from Cassino to San Giovanni Rotondo.