The sun produces a continual stream of radiation which flows outward in all directions, some of it hitting the earth. This is a good thing because without the solar radiation, Earth would be a frozen ball of ice or a lifeless hunk of rock like Mercury. However, the radiation isn't entirely helpful. Some bandwidths can cause severe problems and it would be just as true to say that if there was no protection from it, life in the world, as it is known, would probably not be able to exist. Thankfully, the earth's magnetic field helps to protect the planet from being overwhelmed by the solar radiation.
The sun produces highly energetic radiation from the very short wavelength gamma rays to much longer wavelength infrared radiation. Short wavelength radiation can be lethal in the amounts that stream toward the earth. Even an excess of infrared, which has a longer wavelength can cause damage. Infrared radiation is the wavelength associated with warmth in sunshine and sunburn.
The particles that are sent toward the earth have an electrical charge. That is, they are usually either positively or negatively charged. When these come in contact with a magnetic field, which is also electrically charged field, the majority of the particles are deflected away from the object generating the magnetic field. As a rule, the stronger the magnetic field, the more particles that will be deflected. As it happens, for the size of the planet, Earth has a rather strong magnetic field.
Cause of the magnetic field
It is widely believed that the earth's core is made up of a layer of molten iron and nickle, surrounded by a layer of liquid iron and nickel. As the theory is stated, as one layer rotates around the other, an electromagnetic field is created, much like what is produced by a bar magnet but in vastly greater proportions and called a dynamo effect. This is how energy is created in a generator. Also like a magnet, the earth has both a north and a south magnetic pole.
Shape of the field
If the earth wasn't being bombarded with the charged particles, collectively called the solar wind, the shape of the magnetic field would be almost a sphere, extending outward from the earth. However, the solar wind displaces the field somewhat, leading to a somewhat teardrop shape with the elongated side facing away from the sun. In part, because this has not only been hypothesized, but is measurable, the theory is solid enough to say that the solar particles are being deflected.
Further proof of the theory can be found in the auroras. These are caused by the interaction of highly charged ions from the solar wind with elements in the atmosphere. It is no mistake that the aural light display occurs most strongly at the north and south magnetic poles of the earth. As the theory states, the point at which the magnetic strength is the weakest, the magnetic poles, the energetic particles should be able to reach closer to the earth's surface, where there is more atmospheric gasses, thus being able to interact more rigorously, creating auroras.
Since solar radiation is electrically charged and is affected by the earth's magnetic field, it stands to reason that one of the main causes of the deflection of the radiation would be the magnetic field. At the same time, it lets the type of radiation through that is needed in order for life to keep on ticking on the planet.