Spaniard Martin qualified on pole at Motegi, romped to victory in the Sprint race and claimed his first wet race win in Sunday’s feature length race.
With spots of rain falling before the start it was declared a flag to flag race and as the rain fell heavier, the front runners came in to the pits to change to theie wet set-up machines.
It was Martin who was first out of the pit lane but he dropped to ninth on lap three at Turn 11 when he ran wide under braking.
After regaining his rhythm he quickly made progress through the traffic to again lead the race by lap six.
The 25-year-old was in control at the front, opening over a second of a gap by half-race distance over Bagnaia on the factory Ducati before the red flags came out on lap 13, as conditions worsened.
In the restart the red flags were out again before the riders completed a lap with Martin declared the winner from Bagnaia with Marc Marquez on the Repsol Honda claiming his first podium of the season in third.
Martin said: “It was risky on the first lap because we were on slicks and it started to rain quite a lot. At Turn 11 I let Miller and Pecco overtake me and I was able to see what they were doing and when they stop I say ‘OK, it’s flag to flag and I change my bike’.
"I was the first one of the wet guys and I almost crashed in corner three but I was able to recover and make that gap to Pecco. It was not easy but I was able to do my first victory in the wet. I’m super happy.”
Red Bull KTM Ajo’s Pedro Acosta extended his lead in the Moto2 world championship to 50 points after finishing third behind Idemitsu Honda Asia team-mates Somkiat Chantra and Ai Ogura.
The best British finisher was GASGAS Aspar rider Jake Dixon in fourth.
Jaume Masia now leads the Moto3 championship after winning in Japan.