A construction machine comprising: a hydraulic pump driven by an electric motor; a working mechanism driven by hydraulic oil delivered from the hydraulic pump; a first battery that is configured of a plurality of cells (22A-22N) series-connected to each other and supplies power to the electric motor; a cell voltage detector (24A-24N) that detects a cell voltage of each of the plurality of cells (22A-22N); a battery controller to which power is supplied from a second battery and that executes balancing control for reducing variation in the cell voltage of the plurality of cells (22A-22N); and a key switch having a drive position for driving the electric motor and a stop position for stopping the electric motor, characterized in that: the battery controller calculates a first time as a remaining time required until the balancing control is completed when the key switch is switched from the drive position to the stop position; calculates a second time as a time during which it is possible to keep the voltage of the second battery to be equal to or more than a predetermined given voltage value even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon a voltage state of the second battery; calculates a third time as a time during which it is possible to keep the charging rate of the plurality of cells (22A-22N) of the first battery to be equal to or more than a predetermined given charging rate even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon the charging rate of the plurality of cells (22A-22N) of the first battery; and executes the balancing control by a minimum time out of the first time, the second time and the third time; wherein the battery controller executes the balancing control in a time range during which a voltage of the second battery becomes equal to or more than the predetermined given voltage value and the charging rate of the plurality of cells (22A-22N) of the first battery becomes equal to or more than the predetermined given charging rate value after the key switch is switched from the drive position to the stop position. a hydraulic pump driven by an electric motor; a working mechanism driven by hydraulic oil delivered from the hydraulic pump; a first battery that is configured of a plurality of cells (22A-22N) series-connected to each other and supplies power to the electric motor; a cell voltage detector (24A-24N) that detects a cell voltage of each of the plurality of cells (22A-22N); a battery controller to which power is supplied from a second battery and that executes balancing control for reducing variation in the cell voltage of the plurality of cells (22A-22N); and a key switch having a drive position for driving the electric motor and a stop position for stopping the electric motor, characterized in that: the battery controller calculates a first time as a remaining time required until the balancing control is completed when the key switch is switched from the drive position to the stop position; calculates a second time as a time during which it is possible to keep the voltage of the second battery to be equal to or more than a predetermined given voltage value even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon a voltage state of the second battery; calculates a third time as a time during which it is possible to keep the charging rate of the plurality of cells (22A-22N) of the first battery to be equal to or more than a predetermined given charging rate even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon the charging rate of the plurality of cells (22A-22N) of the first battery; and executes the balancing control by a minimum time out of the first time, the second time and the third time; wherein the battery controller executes the balancing control in a time range during which a voltage of the second battery becomes equal to or more than the predetermined given voltage value and the charging rate of the battery controller calculates a first time as a remaining time required until the balancing control is completed when the key switch is switched from the drive position to the stop position; calculates a second time as a time during which it is possible to keep the voltage of the second battery to be equal to or more than a predetermined given voltage value even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon a voltage state of the second battery; calculates a third time as a time during which it is possible to keep the charging rate of the plurality of cells (22A-22N) of the first battery to be equal to or more than a predetermined given charging rate even when the balancing control continues to be executed in a state where the key switch is in the stop position based upon the charging rate of the plurality of cells (22A-22N) of the first battery; and executes the balancing control by a minimum time out of the first time, the second time and the third time; wherein the battery controller executes the balancing control in a time range during which a voltage of the second battery becomes equal to or more than the predetermined given voltage value and the charging rate of the plurality of cells (22A-22N) of the first battery becomes equal to or more than the predetermined given charging rate value after the key switch is switched from the drive position to the stop position.