The Irish province, leading 21-19, were penalised on the half-way line and full-back Hayward made them pay, helping to lift Treviso off the bottom of the table.
Although the losing bonus point helped Connacht qualify for the top four for the first time since the competition changed format to home and away fixtures in 2003-04, the defeat hampers their hopes of a home semi-final tie.
Connacht, who host Glasgow Warriors in their final game, had not scored a try at the Stadio Comunale di Monigo since April 2013, but they soon ended that drought by crossing twice in the first 14 minutes.
Rory Parata spotted a gap and dived over in the seventh minute and then Fionn Carr latched on to a kick to double their advantage, with both scores converted by John Cooney.
But the hosts, who have lost the last five games and beaten Connacht only once since 2011, responded with tries from Luca Morisi and Braam Steyn in the space of five minutes to narrow the deficit to 14-12 at half-time.
A converted penalty try moved Treviso 19-14 ahead in the 46th minute and, after Peter Robb's 52nd-minute effort appeared to hand Connacht the win, Hayward denied them at the death.