Ducati's Francesco Bagnaia kept his MotoGP title defence alive with a victory at the Malaysian Grand Prix in Sepang on Sunday.