The Gresini rider passed long-time leader Miller on the factory team Ducati late on and cleared off by two seconds to return to the top of the standings with his first podium since his debut win in Qatar.
Miller grabbed the holeshot from second on the grid at the start, while Marquez went backwards to last as his Honda juddered off the line.
Poleman Jorge Martin gave chase to Miller ahead of Francesco Bagnaia and Bastianini on his 2021-spec Ducati, with reigning world champion Fabio Quartararo briefly holding fifth on his Yamaha. But the lack of top speed would soon see the Frenchman shuffled back to eighth by the charging Ducatis and Suzuki duo of Alex Rins and Joan Mir.
Marquez recovered to 17th on the opening lap and by lap seven of 20 was back into the top 10 having overtaken his ill Honda teammate Pol Espargaro.
Bastianini was cut slightly adrift of the lead duo of Miller and Martin – who traded places at the end of the opening lap, with the former holding firm – by the fifth tour but rallied when Miller started to break away from a struggling Martin on the Pramac GP22.
The Italian was briefly demoted by Rins at the big stop into the Turn 11 hairpin on lap 10, but easily blasted his way back through into third on the back straight into Turn 12. By this point Miller had started to pull away from Martin by 0.4 s, which would extend to close to eight tenths as Bastianini dispatched of the Pramac rider at Turn 1 on lap 12.
Bastianini steadily chipped away at Miller’s lead as the factory team Ducati rider’s pace started to fade, while Rins moved into third ahead of Martin at Turn 7 on lap 12.
On lap 16 of 20, Bastianini made his decisive move on Miller into Turn 12 at the end of the back straight and shut the door on any possible retaliation. From that point, Bastianini opened up a gap that Miller could do nothing about, with Rins fast-approaching his rear tyre.
Bastianini had a clear run to the checkered flag to become MotoGP’s first repeat winner in 2022 and take a five-point lead in the championship.
Rins put a move on Miller on the last lap at Turn 11 but was immediately re-passed by the rapid-in-a-straight-line Ducati.
But the Suzuki rider kept on Miller’s rear and pulled off a textbook pass into the penultimate corner to snatch second away from the Ducati to move into second in the standings.
His teammate Joan Mir was just 1.6s away from the final podium spot in fourth as Bagnaia could only manage fifth having started from the front row.
After his lap one disaster, Marquez recovered to sixth at the checked flag in a sublime charge through the pack. As the likes of Martin and Pramac team-mate Joahnn Zarco started to fade, Marquez and Quartararo picked them off easily.
Over the final few tours, Marquez and Quartararo engaged in a battle reminiscent of their 2019 race fights – though the pair nearly came to blows on the penultimate lap when Marquez had a moment rounding Turn 6 and almost touched Quartararo.
Marquez had taken sixth from the Yamaha rider on lap 14, with the Frenchman trying to fight back when they almost touched on lap 19.
The moment sent Quartararo out wide into Turn 7 and allowed Marquez to come back through to take sixth by just 0.143s.
Martin faded to a disappointing eighth in the end ahead of Zarco, while Maverick Vinales took top Aprilia honors from teammate Aleix Espargaro in 10th late on.
Brad Binder brought KTM’s miserable COTA weekend to a close in 12th ahead of Pol Espargaro, while LCR’s Takaaki Nakagami and RNF Racing’s Andrea Dovizioso completed the top 15 after Yamaha’s Franco Morbidelli was demoted one spot for exceeding track limits on the last lap.
VR46 Ducati rider Luca Marini headed KTM’s Miguel Oliveira and his Tech3 counterparts Raul Fernandez and Remy Gardner, with Gresini’s Fabio Di Giannantonio and RNF’s Darryn Binder – who pulled into pit lane briefly late on – the last of the finishers.
LCR’s Alex Marquez and VR46 rookie Marco Bezzecchi were early fallers.