In consideration of the initial singularity of the solution, a temporally second-order fast compact difference scheme with unequal time-steps is presented and analyzed for simulating the subdiffusion problems in several spatial dimensions. On the basis of sum-of-exponentials technique, a fast Alikhanov formula is derived on general nonuniform meshes to approximate the Caputo’s time derivative. Meanwhile, the spatial derivatives are approximated by the fourth-order compact difference operator, which can be implemented by a fast discrete sine transform via the FFT algorithm. So the proposed algorithm is computationally efficient with the computational cost about \(O(MN\log M\log N)\) and the storage requirement \(O(M\log N)\), where M and N are the total numbers of grids in space and time, respectively. With the aids of discrete fractional Grönwall inequality and global consistency analysis, the unconditional stability and sharp H1-norm error estimate reflecting the regularity of solution are established rigorously by the discrete energy approach. Three numerical experiments are included to confirm the sharpness of our analysis and the effectiveness of our fast algorithm.