A construction machine including: an upper turning body comprising a work machine; a lower traveling body that supports the upper turning body so as to be capable of turning via a turning axis; an electric turning motor that causes the upper turning body to turn; a rotation speed acquisition unit that acquires a value representing a rotation speed of the upper turning body; characterized in that the construction machine further includes an attitude sensor that detects a current attitude of the upper turning body; a torque command value generation unit that outputs a torque command value to the electric turning motor according to an operation amount of an operation part; a reference angular acceleration calculation unit that calculates a reference angular acceleration to be generated when the electric turning motor is driven at the torque command value; a reference gravity torque calculation unit that calculates a reference gravity torque which is a torque component generated about the turning axis by gravity in a reference attitude on the basis of the current attitude and a deviation between an actual angular acceleration obtained from the rotation speed and the reference angular acceleration; a gravity compensation torque calculation unit that calculates a gravity compensation torque for compensating a torque component generated about the turning axis by gravity in the current attitude on the basis of the reference gravity torque and the current attitude; and a correction unit that corrects the torque command value with the gravity compensation torque so as to cancel a torque component generated about the turning axis by gravity in the current attitude. an upper turning body comprising a work machine; a lower traveling body that supports the upper turning body so as to be capable of turning via a turning axis; an electric turning motor that causes the upper turning body to turn; a rotation speed acquisition unit that acquires a value representing a rotation speed of the upper turning body; characterized in that the construction machine further includes an attitude sensor that detects a current attitude of the upper turning body; a torque command value generation unit that outputs a torque command value to the electric turning motor according to an operation amount of an operation part; a reference angular acceleration calculation unit that calculates a reference angular acceleration to be generated when the electric turning motor is driven at the torque command value; a reference gravity torque calculation unit that calculates a reference gravity torque which is a torque component generated about the turning axis by gravity in a reference attitude on the basis of the current attitude and a deviation between an actual angular acceleration obtained from the rotation speed and the reference angular acceleration; a gravity compensation torque calculation unit that calculates a gravity compensation torque for compensating a torque component generated about the turning axis by gravity in the current attitude on the basis of the reference gravity torque and the current attitude; and a correction unit that corrects the torque command value with the gravity compensation torque so as to cancel a torque component generated about the turning axis by gravity in the current attitude.