Lorenzo Dalla Porta pipped Jorge Martin to take his maiden Moto3 win in a dramatic San Marino Grand Prix, while points leader Marco Bezzecchi suffered a late crash.
Gabriel Rodrigo grabbed the holeshot into Turn 1 at the start, while Fabio Di Giannantonio seized second from Gresini teammate Martin, who eventually dropped to seventh over the opening lap.
Di Giannantonio took the lead from Rodrigo into Quertia, with Bezzecchi following suit at the first corner on the following tour.
Bezzecchi managed to slingshot past Di Giannantonio through the fast Curvone to lead at the end of lap two, while Martin made his way through on Jaume Masia at the last corner to move into fifth.
Seconds after completing that move, Masia highsided as he applied the throttle, causing a pile-up involving Enea Bastianini, Nicolo Bulega, Ayumu Sasaki and Aron Canet – the latter two taken to the medical centre for checks.
That mass crash saw the top five of Bezzecchi, Di Giannantonio, Lorenzo Dalla Porta, Martin and Rodrigo break away from the rest, with an aggressive battle for the podium ensuing.
Bezzecchi led across the line at the start of the penultimate lap after recovering from an hard move by Di Giannantonio at Rio the tour before.
As the lead group heading through Turn 15, Bezzecchi crashed, narrowly avoiding title rival Martin, and giving the lead back to Dalla Porta.
Di Giannantonio launched a final assault on the lead into the final corner, but ran wide and allowed Dalla Porta and Martin to draw alongside.
Dalla Porta held on for his debut win by just 0.058s, with Di Giannantonio a further 0.064s behind his teammate Martin, who regains the championship lead by eight points over the non-finishing Bezzecchi.
RBA's Rodrigo was a few tenths back in fourth, with the sole remaining Prusetl KTM of Jakub Kornfeil a distant fifth.
Albert Arenas completed the top six ahead Dennis Foggia, who takes his best result of the season in seventh. Darryn Binder, Andrea Migno and Niccolo Antonelli rounded out the top 10.
Wildcard Kevin Zannoni added his name to the long list of crashers, but rejoined 20th on TM Racing's grand prix debut. John McPhee, Alonso Lopez and Tatsuki Suzuki also fell out of the race.