" but how does it work and why is it necessary in circuits?"
Look at circuit ground that way; there are many signals and different voltages to be found in a complex electronic circuit. They all require to have a common reference point to make sense. That reference point is conveniently the ground connection.
It does not *have* to be ground but, since 0V is usually the common rail for the voltages, tying it to ground (chassis, shield, earth) gives a safety factor. If any of the voltage carrying wires would accidentally come loose and touch a grounded metal part, a fuse would blow and prevent further damage (fire, etc.).
Tying the signal return connection also to ground does eliminate a great deal of radiated interferance that could otherwise be picked up by floating signal lines. This part is difficult to explain, I'm sure if you search a little on the net you will find good tutorials on this subject. I't quite a bit more complex than it looks at a first glance.
Steve pointed out the reasons for using actual ground (earth) connections with power distribution systems.
Klaus