As we well know, the main characteristic of magnets is that they have a south pole (negative) and a north pole (positive). In two different magnets the poles of different sign attract each other and the poles of the same sign repel each other.
If we place two magnets aligned and in the middle a third magnet in the perpendicular direction, the natural tendency will be to rotate aligning with the other two. He will have made a quarter of a turn. What would we have to do to keep it spinning? If you could change the polarity of the central magnet it would continue to spin looking again at the equilibrium position again. But this can not be done. What can be done is to replace the central magnet with an electromagnet. An electromagnet can be changed the direction of the electric current that circulates in it and then the polarity changes.
Generation of an electric field within a magnetic field
A direct current motor requires a stator, and a rotor inside it. The stator is the fixed part where fixed magnets are placed to create a magnetic field that passes through the rotor. The rotor is the rotating part. In the rotor a continuous round-trip current is circulated which leaves the center of the rotor in the middle.
When an electric current flows through a conductor in the middle of a magnetic field, an electromotive force is generated in the conductor that causes it to move, and therefore to rotate. Once it has reached the equilibrium position, the direction of the current flowing through the conductor is switched and the rotor rotates again looking for the equilibrium position.