Formolo finished the 150km ride from Chiavari to La Spezia in a time of 3hr 47min 59sec, just 22sec ahead of a small group of chasers including race Alberto Contador and Richie Porte.
It was the 22-year-old's maiden professional win on his first season with Cannondale-Garmin, and was fully deserved after a difficult stage whose technical finish had several riders in trouble.
Formolo was among the 14 riders still remaining from a larger, earlier breakaway and as they rode over winding terrain on their way towards the Ligurian port town of La Spezia the young Italian used his climbing skill, and some perfect timing, to make the difference.
With 13km remaining Formolo soloed away from the leading bunch to build a lead of a handful of seconds on Frenchman Amael Moinard and Italian Giovanni Visconti, with Contador further back in another chase group being led by Fabio Aru's Astana team.
By the time he crested the final small climb of the day, 10km from the finish, Formolo had taken his advantage on Moinard and Visconti to 32sec, with Contador's chasers a handful of seconds behind.
It was a nervous 10km descent to the finish line for Formolo, who was constantly turning around to check the progress of his chasers, and he waited until the final 100 metres of the home straight before throwing his arms in the air in triumph.
Perhaps not realizing there had been a solo breakaway ahead of him, Clarke also threw his arms up in the air after he won the bunch sprint for second place, only to slap his hands on to the top of his helmet in embarrassment when told by Visconti the stage had already been won.
Nevertheless, the Australian domestique's endeavours were enough to hand him the race leader's pink jersey, keeping the 'maglia rosa' in the Orica team for one more day.
Clarke, who is not an overall race contender, leads Colombian teammate Esteban Chaves by 10secs in the general classification with Czech contender Roman Kreuziger third at 17.
Contador, bidding for a rare Giro d'Italia-Tour de France double this year, is fourth at 17 with Australin contender Porte 20secs further adrift ahead of Wednesday's 152km fifth stage.
It begins in La Spezia and finishes with a 17km climb to the summit of the Abetone climb.