Masnada was strong enough to hold on to an advantage gained by a late attack to finish the stage five seconds ahead of a select group of contenders for the overall win.
Tao Geoghegan Hart (Team Sky) won the sprint for second place ahead of Rafal Majka (Bora-Hansgrohe) and Vincenzo Nibali (Bahrain-Merida).
Pavel Sivakov (Team Sky) retains the overall lead after coming home in the same group, five seconds down on Masnada.
The main action of the day started on the final climb as Majka’s attack was matched by Nibali with six kilometres to go and prompted Chris Froome (Team Sky) to take up the reins of pursuit in the main group.
Froome had lost some time on the previous stages, but showed that his form is far from awful, acting as the domestique for the race leader, as he towed teammates Sivakov and Geoghegan Hart back up to Nibali and Majka.
The pace-making whittled the front group down to just seven riders – Jan Hirt (Astana) and Mattia Cattaneo (Androni-Sidermec) also managed to follow the fierce tempo being set, before a regrouping on the plateau after the top of the climb.
Together with Evgeny Shalunov (Gazprom-Rusvelo), Masnada managed to regain contact as the road levelled out in the closing kilometres, and the Italian was very quick to spot an opportunity to take a big victory. Jumping with 1500 metres to go, he attacked quickly established a winning gap and was able to hold off the bigger names behind to take out the stage win.