The Earth rotates because of conservation of angular momentum. An ice
skater provides a common example of this effect; as an ice skater
brings his or her arms in closer to his or her body, he or she will
spin faster.
As the solar system formed from condensing gases, it would by
accident have had some angular momentum. In other words, the average
velocities of the material on different parts of the cloud weren't
quite the same. When nearly all the mass collapsed into the Sun, the
only way for the angular momentum to stay the same was for parts of the
cloud to stay out of the central star and to rotate quickly around the
star. That's why all the planets orbit the same way around the sun.
When that material condensed further, forming the Earth and the other
planets, these also had to spin about their axes to keep the angular
momentum from changing. Most of the planets spin around axes close to
the same as the one around which they orbit the Sun. However, accidents
that happened to each planet affected the exact rate and direction of
the spin.
The Earth has not always rotated at 23.5 degrees. Many factors
effect the angle of Earth's tilt. The motion of large air masses can
change its tilt by measurable amounts even today. During the major Ice
Ages, large sheets of ice on Earth's surface and lowered sea level may
have caused the Earth to have an even larger tilt. Small changes in the
Earth's surface like continental drift and variations of sea level
acting over million of years time may change the tilt significantly.
Last, the Earth's spinning was affected by collisions with other
bodies while it was forming. The last major impacts with a body 1000
kilometers across was about 4.5 billion years ago. The impact tore a
chunk of material out of the Earth, and formed a ring of rock and
debris around our planet which later became the Moon. At least that's
our best current understanding of the process.
(published on 10/22/2007)