Matera — in the southern Basilicata region — is known for its cave dwellings, which were inhabited until the 1950s.
Almeida stopped on the side of the road to fix the radio under his jersey with 37 kilometers to go when he was hit. Sprinter Fernando Gaviria went down in the same incident, but both riders quickly got going again.
Almeida, a Portuguese rider with the Deceuninck-Quick Step team, remained 43 seconds of Spanish rider Pello Bilbao.
Démare, a French rider with the Groupama-FDJ team, also won Stage 4 in a three-way photo finish.
This was Démare’s third career win at the Giro. He also won a stage in Modena last year to go with his two stage victories at the Tour de France in 2017 and 2018.
Four riders formed an early breakaway and established a lead of more than 10 minutes on the peloton before eventually being reeled back in.
James Whelan was the last of the breakaway riders to be caught, with 14 kilometers to go.
Stage 7 on Friday, a mostly flat 143-kilometer leg from Matera to Brindisi, also sets up well for sprinters.