Italian Francesco Bagnaia overtook Portuguese Miguel Oliveira on the final corner on Sunday to win the Moto2 Austrian Grand Prix and regain first place in the standings.
Oliveira (KTM) started two points ahead of Bagnaia (Kalex) and grabbed an early lead.
The pair pulled clear of the field with Bagnaia on Oliveira's rear wheel trying to find a way past.
The Italian briefly grabbed the lead with five, four and two laps to go, but each time the Portuguese rider struck back on the next corner.
The same thing happened on the last lap, but Bagnaia then conjured one last attack, and this time Oliveira could not reply.
"When it was possible to overtake him and when I did on the last corner it was amazing," Bagnaia said.
The victory means Bagnaia leads Oliveira by three points in the standings.
"I'm very happy for leadership of the championship again," he said.
Oliveira was disappointed with the result.
"It sucks a little bit to lose like this," said Oliveira. "It was a great battle. I left it all on the track. He overtook me in the second last corner. I tried on the last corner, had my rear wheel in the air, tried to break the bike."
Italian Luca Marini (Kalex) was third after Spaniard Alex Marquez (Kalex), who is a distant third in the standings, crashed on the last corner.
In Moto3, Italian teenager Marco Bezzecchi won to extend his lead over injury-stricken Jorge Martin at the top of the riders' standings.
KTM rider Bezzecchi, 19, who started from pole for the first time in his career, held off Enea Bastianini and Martin at Spielberg to move 12 points clear of the Spaniard in the championship race.
It was an incredible podium finish from the 20-year-old Martin, who missed the Czech Grand Prix last weekend after damaging his wrist in a crash in practice.
The Honda man, despite racing with a broken wrist, finished third in a brave ride to keep his hopes of a first world title alive.
Martin has won five races this term, but also failed to finish three times before sitting out the action in Brno.
Francesco Bagnaia won a thrilling race to retake the Moto2 championship lead
Bezzecchi claimed his second win of the season to extend his championship lead