Permanent magnet synchronous motors (PMSMs) with inverters are widely used in electric vehicles (EVs). However, current harmonics caused by the nonlinearity of the inverter generate torque ripples and give rise to torsional vibration in the vehicle driveline. This paper proposes a new compensation method to suppress the torque ripples. This method extracts the 6th-order harmonic component online from the d-axis and q-axis currents with the approximate Fourier transform, and adopts a harmonic current PI regulator to calculate compensation voltage, which is added to the voltage reference to compensate the nonlinearity of the inverter. After correcting the current distortion and improving the motor torque smoothness, the torsional vibration of the driveline caused by the motor pulsating torque is reduced. According to the simulation results, the 6th-order of motor torque ripple and the torsional vibration response is reduced about 26–28%, which confirms the validity of the proposed strategy. The proposed method does not need any additional hardware and can be implemented broadly in PMSM drives.