The Italian claimed his first win, of an injury wrecked season, with a faultless performance at the 5.534km Sepang International circuit.
The 25-year-old Lenovo Ducati rider started from third on the grid and was in control of the 20-lap race from the end of the first lap to the chequered flag to become the seventh different winner of 2023.
“I’m so tired,” said an exhausted Bastianini. “I gave 100% today.
“Today I didn't want anything else – I just wanted to win.
"I didn't care about the rest and I knew I could do it.
"In the race I pushed from the start, maintaining the gap, but I was totally at the limit and couldn't give anything more but, in the end, the victory came.
"Only my family and friends know what I’ve had to do to arrive here. It’s fantastic!”
It was a superb weekend for Alex Marquez on the Gresini Ducati with the 27-year-old finishing second after claiming his second Sprint race victory the previous day.
The title battle between Pecco Bagnaia and Jorge Martin is still 14 points with two rounds remaining in the series.
Martin had closed the gap to eleven after finishing second in the Sprint race but had no answer for pole setter Bagnaia after the opening laps when the two went head-to-head.
In the end, the Lenovo factory Ducati's Bagnaia completed the rostrum, well clear of his rival on the Prima Pramac Ducati.
"This is the first time since Austria that I’ve beat him in the same conditions so I’m happy for that,” said Bagnaia. “It was very important to do it before Qatar.”
Martin was disappointed with fourth.
“It’s not what I expected,” he said. “I expected to fight for the podium or for the victory.
"It was strange because I tried to push to put some pressure on him so maybe he’d make a mistake, but I started to be close to crashing, so I decided that’s not what I wanted.
"So that’s the maximum I could do today."
Elsewhere, Pedro Acosta claimed his maiden Moto2 World Championship for Red Bull KTM Ajo.
The Spaniard, who will move to MotoGP in 2024, finished second to Fermin Aldeguer, who took his third win of the season with Marcos Ramirez making it an all-Spanish podium.
Brits Jake Dixon and Sam Lowes finished fifth and seventh respectively.
VisionTrack Racing Teammates Scott Ogden and Josh Whatley finished in the points in the Moto3 race won by Collin Veijer from the Netherlands.