The win provided an immediate boost for Paolo Vanoli on his return as Fiorentina head coach, ending their difficult start to the campaign and lifting La Viola off the bottom of the table.
Venezia created the first clear openings, with John Yeboah heading wide before Fiorentina goalkeeper Filip Stankovic denied Mastantuono at close range. Cher Ndour then fired into the side netting, while Alex Jimenez narrowly missed the target as both teams looked dangerous going forward.
Venezia took the lead against the run of play midway through the first half. Gianluca Busio drove through the middle before finding Akor Adams, who struck a powerful first-time finish into the far corner for his first Serie A goal.
Fiorentina responded almost immediately, with Mastantuono turning the game around in a remarkable two-minute spell.
The Real Madrid loanee cut inside from the right before sending a low left-footed shot into the bottom corner. Moments later, he reacted quickest to a loose ball and fired into the opposite corner, with his effort taking a touch off the post on its way in.
Fiorentina almost extended their advantage before half-time, but Stankovic made an important save with his legs to deny Alieu Njie after the forward had been played through on goal.
Venezia applied pressure after the restart, but Fiorentina remained dangerous on the counter. Their approach paid off with less than 25 minutes remaining when Mateo Pellegrino made it 3-1.
Nicolo Fagioli cleared the ball from inside his own half and Pellegrino raced onto it before keeping his composure to fire a left-footed finish into the bottom corner.
Venezia continued to push, with Thorir Johann Helgason forcing a save from David de Gea from distance, but Mastantuono completed his hat-trick soon afterwards.
The 19-year-old followed a looped pass from Ndour and saw his initial effort saved by Stankovic, only for the ball to rebound off Mastantuono and end up in the net.
Venezia managed a late consolation when Antoine Hainaut smashed a right-foot volley past De Gea with three minutes remaining, but Fiorentina held on comfortably to secure a much-needed victory.
READ MORE: Pedro Neto signs new Chelsea deal until 2032