Earth's magnetic field acts as a shield that diverts charged particles from the solar wind away from tropical and temperate latitudes thus preventing the loss of atmosphere due to impacting particles from the sun. Planets without strong magnetic fields tend to lose their atmospheres to space.
The Earth generates a magnetic field from the convection of molten metals, primarily iron and nickel, near its core. The twisting effect of these metals relative to the planet's spin generates a magnetic field that is usually strong and consistent. While the field is active, charged particles from the sun are deflected around the Earth along the field's lines of force. Some particles from the solar wind are carried along the field's lines to the north and south magnetic poles, where they are accelerated into the atmosphere and produce the aurora borealis and australialis. Without the protection of the magnetic field, the steady pressure of the solar wind would gradually ablate the upper reaches of the Earth's atmosphere until little air is left. This process takes a long time, however, and the Earth's magnetic field has weakened and shifted polarity many times in the past without noted ill effects on life on the surface.