Simply put, an electric motor can be defined as a machine that converts electrical energy into mechanical energy. The first electric motors date back to 1740s when Scottish monk Andrew Gordon created electrostatic devices. Peter Barlow created the first rotating device that was driven by electromagnetism back in 1822 and named it Barlow's Wheel. The first real electric motor based on rotation, however, is credited to German speaking Prussian Moritz Jacobi back in May 1834. Walter Baily demonstrated the first induction motor back in 1879.
As mentioned, the electric motor relies on electromagnetism. Upon placement of a coil carrying current (rectangular coil) in a magnetic field, a torque is generated that acts on the coil and forces it to rotate continuously. The rotation of coil can drive the shaft attached to it, therefore, completing mechanical work. In short, the rotational motion is because of magnetic pulling and repelling.
Alot more info here.