Gravity and inertia:
As the Earth coalesced from the primordial cloud that formed our solar system and gravity pulled it into a tighter sphere, the overall motion in the material that formed it gained angular momentum. This effect can be observed in the increased rate with which a figure skater spins as they pull their extremities closer to their axis of rotation.
Once the Earth reached a maximum density and speed of rotation, it began to spin at a reduced speed. Days are slowly getting longer as angular momentum is given up to external forces such as the tidal forces of the Moon and Sun, caused by gravitational attraction.