Reducing the resistance of compressible flow around a blunt body is of great interest in engineering applications, while an efficient shape optimization method for compressible flows remains far from well established, especially for high Mach numbers. To this end, a volume penalization method for simulating compressible flows past a no-slip and isothermal solid is established by introducing an artificial body force and a heat sink into the governing equations. The level-set functions are introduced as design variables, and the cost functional is defined as the total drag acting on the solid. Then, a continuous adjoint-based shape optimization algorithm for drag reduction is developed by deriving the adjoint equations, the adjoint boundary conditions, and the shape update formula. Both the forward and adjoint simulations are verified by existing studies. The results show that the relative deviations of the drag coefficients obtained in the present study from those reported in the reference studies are around 5% at most, and also a comparable drag reduction rate and also optimal shapes can be reproduced by the present optimization scheme for benchmark problems at relatively low Mach numbers considered in previous studies. Finally, the present method is applied to shape optimization of an initially two-dimensional cylinder and also a three-dimensional sphere in the transonic regime of Ma∞ = 1.2. The drag reduction of over 20% is achieved for both two-dimensional and three-dimensional cases.