Fever occurs typically when a virus or bacteria invades the body. The immune system produces chemicals called pyrogens, which trick the brain's hypothalamus (where the body's thermostat resides) into sensing an artificially cool body temperature.
The brain responds like any good warm-blooded animal's would, by knocking the thermostat up a few notches. Blood rushes to the body's core, heating the body overall but cooling the surface — hence the chills. The body's metabolic rate goes up and and muscles contract.
The immune system's goal: to encourage chemical reactions that will increase production of disease-fighting antibodies, stimulate activity of white blood cells and even inhibit the invading microbe's growth.