1. A magnetic sensor comprising a sensor gear attached to a rotor of a motor, a detection portion which outputs a signal representative of the presence or absence of a plurality of teeth provided on an outer periphery of the sensor gear at predetermined intervals, a sensor holder which holds the detection portion, a sensor mounting base to which the sensor holder is attached, and a screw by which the sensor holder is attached to the sensor mounting base,wherein
the detection portion on the sensor holder attached to the sensor mounting base is arranged to be opposed to the outer periphery of the sensor gear at a predetermined distance,
the sensor holder has a holder body which holds the detection portion and a portion to be fastened which is fastened to the sensor mounting base by the screw,
the portion to be fastened is provided integrally with one side of the holder body that is located to face opposite the sensor gear, and
at least the portion to be fastened of the sensor holder is made of a material having an elastic modulus lower than the materials of the sensor mounting base and the screw.