A work machine comprising: a working head including a holding tool configured to pick up and hold a component, a rotating device configured to rotate the holding tool about an axis of the holding tool, a pivoting device configured to pivot a pivotable part of the holding tool between a first attitude in which an end portion of the holding tool faces downward and a second attitude in which the end portion of the holding tool faces sideways; a moving device configured to move the working head; an imaging device configured to image the component to be picked up, so that a position of the component can be acquired based on the imaging data; and a control device configured to control operation of the working head and the moving device, the control device including an operation control section configured to, when the working head moves along a movement path to a target position after the component has been picked up by the holding tool in the first attitude, cause the pivotable part of the holding tool to pivot from the first attitude to the second attitude, and to cause the holding tool to rotate from a holding angle that is a rotation angle when the component was picked up to a target angle, wherein the work machine is configured to determine as to whether the component held by the holding tool will come into contact with a portion of the work machine based on the position and dimensions of the component to be held acquired from the imaging data, the length dimension of the pivotable part and the movement path of the working head, and the operation control section is configured to, along with causing the pivotable part of the holding tool to pivot from the first attitude to the second attitude, when rotating the holding tool from the holding angle to the target angle, in a case in which it is determined that the component held by the holding tool will contact a portion of the work machine, perform control of operation of at least one of the rotating device or the pivoting device such that the component held by the holding tool avoids contacting a portion of the work machine. a working head including a holding tool configured to pick up and hold a component, a rotating device configured to rotate the holding tool about an axis of the holding tool, a pivoting device configured to pivot a pivotable part of the holding tool between a first attitude in which an end portion of the holding tool faces downward and a second attitude in which the end portion of the holding tool faces sideways; a moving device configured to move the working head; an imaging device configured to image the component to be picked up, so that a position of the component can be acquired based on the imaging data; and a control device configured to control operation of the working head and the moving device, the control device including an operation control section configured to, when the working head moves along a movement path to a target position after the component has been picked up by the holding tool in the first attitude, cause the pivotable part of the holding tool to pivot from the first attitude to the second attitude, and to cause the holding tool to rotate from a holding angle that is a rotation angle when the component was picked up to a target angle, wherein the work machine is configured to determine as to whether the component held by the holding tool will come into contact with a portion of the work machine based on the position and dimensions of the component to be held acquired from the imaging data, the length dimension of the pivotable part and the movement path of the working head, and the operation control section is configured to, along with causing the pivotable part of the holding tool to pivot from the first attitude to the second attitude, when rotating the holding tool from the holding angle to the target angle, in a case in which it is determined that the component held by the holding tool will contact a portion of the work machine, perform control of operation of at least one of the rotating device or the pivoting device such that the component held by the holding tool avoids contacting a portion of the work machine.