Francesco Bagnaia claimed a dramatic victory at the San Marino Grand Prix after holding off future team-mate Enea Bastianini in Misano.

The 14th race of the MotoGP World Championship went right down to the wire between the two Italians, who will team up at Ducati for the 2023 season.

But despite intense pressure from his compatriot over the final few laps, Bagnaia held his nerve to prevail by a mere 0.034 seconds.

In closing the gap on championship leader Fabio Quartararo, who finished fifth, to 30 points Bagnaia becomes the first Ducati rider to win four successive races.

Maverick Vinales completed the podium, while Andrea Dovizioso finished 12th in the final race of his MotoGP career.

Following a three-place grid penalty in qualifying, Bagnaia started in P5 with Jack Miller having ensured his first pole in four years.

However, the Australian fell in just the second lap after slipping at turn four, while Marco Bezzecchi followed a few turns later.

Bagnaia first led in lap three with Bastianini, Vinales and Luca Marini for company, and Quartararo and Aleix Espargaro further back.

As Marini fell away, a couple of untidy corners saw Vinales also lose ground with eight laps to go; setting up a straight race between Bagnaia and Bastianini for the chequered flag.

Though Bastianini gradually closed the gap over the final four laps, he missed a couple of opportunities to pass as a stubborn Bagnaia held out to maintain his winning streak by the finest of margins.

"I struggled at the start because the grip was not so high," he said. "I was struggling to find some traction. But my feeling with the tyres was getting better lap by lap.

"In the last laps, I was trying to push to open a gap, but Enea was too fast. I'm very happy to win today. It wasn't the best start from P5, but we did it."

TOP 10

1. Francesco Bagnaia (Ducati)
2. Enea Bastianini (Gresini) +0.034
3. Maverick Vinales (Aprilia) +4.212
4. Luca Marini (Ducati) +5.283
5. Fabio Quartararo (Monster Energy Yamaha) +5.771
6. Aleix Espargaro (Aprilia) +10.230
7. Alex Rins (Suzuki Ecstar) +12.496
8. Brad Binder (KTM) +14.661
9. Jorge Martin (Ducati) +17.732
10. Alex Marquez (Honda) +21.986

CHAMPIONSHIP STANDINGS

Riders

1. Fabio Quartararo (Monster Energy Yamaha) - 211
2. Francesco Bagnaia (Ducati) - 181
3. Aleix Espargaro (Aprilia) - 178
4. Enea Bastianini (Gresini) - 138
5. Johann Zarco (Ducati) - 125

Teams

1. Ducati - 279
2. Aprilia Racing - 253
3. Monster Energy Yamaha - 226
4. Pramac Racing - 212
5. Red Bull KTM - 192