Jorge Martin pipped championship leader Marc Bezzecchi to Moto3 victory in the Italian Grand Prix by just 0.019 seconds, with Fabio Di Giannantonion a further 0.024s back.
Poleman Martin seized the advantage off the line and led comfortably into San Donato, while Bezzecchi launched through from fifth to second ahead of Di Giannantonio.
Martin had an 0.8s gap at the front by the end of the opening lap, but was quickly closed down Gresini team-mate Di Giannantonio and Prustel GP's Bezzecchi, who traded places at Savelli on the second tour.
The top three managed to break away from the massive chasing group battling for fourth, and were three seconds clear by the fourth lap.
The leaders ran line astern for much of the remaining laps, with all three taking turns leading the race. However, Martin was able to reclaim first on most occasions into the first corner.
Martin's race almost came undone with eight laps to go when a hare ran in front of him on the entrance to the Casanova corner, but the Gresini rider just missed it and maintained his lead despite having back off slightly.
As the leaders entered the final lap, Bezzecchi used the grunt of his KTM to launch an attack on Martin's lead into the first turn, but ran too wide and allowed both Gresini riders back ahead.
Martin held the advantage as the trio headed into the final corner despite a moment at Palagio a few turns earlier, and nailed his launch onto the pit straight to just hold onto victory, while Bezzecchi edged Di Giannantonio at the chequered flag.
Bezzecchi's second keeps him in the lead of the championship, though Martin has cut his advantage down to just three points.
RBA Racing's Gabriel Rodrigo secured his best result of the season in fourth, with last year's Mugello winner Andrea Migno on the Nieto KTM completing the top five ahead of Leopard's Enea Bastianini.
Tony Arbolino was seventh in his home race ahead of Lorenzo Dalla Porta, Niccolo Antonelli and wildcard Manuel Pagliani, with Aron Canet dropping to 11th after a near-crash in the closing stages.
Adam Norrodin was an early crasher, after a slight nudge from Canet sent him wide and into a vicious highside exiting Borgo San Lorenzo.
The Malaysian was joined by Makar Yurchenko, Jaume Masia, wildacard Stefano Nepa and Denis Foggia on the sidelines.