A tool gripping mechanism includes a tool holder and a shaft to which the tool holder is attached. The shaft is fixed to a rotary shaft of a spindle device. A plurality of magnets are disposed in pairs on concentric circles on surfaces of the tool holder and the shaft which face each other. When the tool holder is in a specific phase with respect to the shaft, the magnets of the tool holder and the magnets of the shaft attract each other, and the tool holder is aligned with respect to the shaft in that phase.