Misano Adriatico, Italy - Spaniard Marc Marquez snatched victory on the final lap at the San Marino Grand Prix on Sunday to close in on a sixth world title.
The Honda rider, starting on the second row, took a third MotoGP win in Misano ahead of France's Fabio Quartararo, on a Yamaha-SRT, who had the lead for most of the race.
"At the end I just decided to go for it," said Marquez, who had been pipped at the line at the last two races in Silverstone and the Dutch GP.
Five-time world champion Marquez won the 77th Grand Prix of his career in all categories to overtake British legend Mike 'the bike' Hailwood.
The 26-year-old has won 51 MotoGP races, 16 Moto2 and ten Moto3.
Marquez now has a 93-point lead on Italian Ducati rider Andrea Dovizioso with six races left this season. Dovizioso finished sixth on Sunday on front of his home crowd.
Pole sitter Maverick Vinales completed the podium for Yahama.
"It was a very tough race," said Quartararo, 20. "It was the first time that I battled like that with Marquez."
Marquez has won five times in Misano and twice before in the MotoGP category in 2015 and 2017.
He matches Italian star Valentino Rossi's record of three wins at the San Marino MotoGP.
Former seven-time world champion Rossi - who last won in Misano in 2014 - finished fourth in his home race.
In Moto2, Spaniard Augusto Fernandez also snatched victory on the final lap to make it back-to-back wins after Silverstone.
The 21-year-old Kalex rider audacious overtaking move on the final lap gave him victory over Italian pole sitter Fabio di Giannantonio.
Spain's Alex Marquez - younger brother of MotoGP world champion Marc Marquez - consolidated his overall world championship lead by finishing third.
In Moto3, Japan's Tatsuki Suzuki started on pole to claim his maiden victory after a thrilling seven-rider battle at the Misano World Circuit Marco Simoncelli, near Rimini in eastern Italy.
Suzuki's victory was charged with emotion as he races for the team of Italian Paolo Simoncelli, whose son Marco died after an accident in 2011, with the Misano circuit named in his honour.