The magneto is a mechanism which generates electrical energy from mechanical energy. More specifically, most magnetos take a rotating component and a static component and produce alternating current. They are most commonly used today in aviation, in the ignition system of reciprocating engine aircraft.
Essentially, the magneto consists of a set of permanent magnets and a coiled wire. When the coiled wire is rotated within the magnetic fields of the permanent magnets, it produces a pulsed, alternating current as the wire moves into and then out of each magnet's field. This is in contrast to a dynamo or generator, which is designed to produce direct current. Some magnetos have fixed magnets and rotate the coiled wire; others have a fixed coil and rotate the magnets, but the output is the same.
The magneto was originally used in automobile engines to provide a current source for the ignition spark plugs. The pulsed power from the magneto could be fed through a transformer to produce very high voltage (but brief) pulses, perfect for spark plugs. Automobiles in the early 20th century typically used magnetos. One advantage to the magneto was that it allowed the car to be started with the application of motion; before electric starter motors became common, cars were started by a crank. That crank would rotate the magneto as well as the engine, generating power for the spark plugs. Early aircraft engines worked the same way; to start them, the ignition system was connected up and the propeller (and the engine crankshaft) were spun by hand. This would cause the magneto to generate power to the spark plugs, and the engine would (hopefully) start, and the person turning the propeller would (hopefully) get out of the way.
Aircraft engines, which needed all the reliability they could get, began to include dual magneto systems. Since the magneto itself was a relatively simple, small mechanism, not that heavy, each cylinder of the engine could have two spark plugs - each fed off a different magneto. This not only provided dual ignition (which meant more efficient fuel burn as well as increased possible fuel burn) but it meant that in the event a magneto failed, the engine would continue working.
Today, in small general aviation aircraft like the Cessna SkyHawk, the engine ignition is done by magnetos. The ignition switch has three settings: 1, 2 and Both. Turning the key to 'start' and then releasing it will leave it in the 'Both' position - this switches both magnetos into their ignition circuits. However, as part of the run up checklist, before flight, dual-magneto airplanes will have an item which directs the crew to test the magnetos individually. To do so, once the engine has started, the ignition is moved from 'Both' to '1', and then back to 'Both' - then to '2' and back. Each time the switch is moved to a single magneto a slight drop in engine RPM should be seen as the engine ignition loses some efficiency as half its spark plugs stop working. If moving the switch to either 1 or 2 does not produce a drop, the crew should immediately have the aircraft checked over by a certified powerplant technician - because what has likely happened is that one ignition circuit has become shorted, or both have shorted to each other. In this case, any failure of the circuit will cause both ignition systems to fail, and this is what pilots call Not A Good Thing(tm). The other possibility is that if one magneto has failed, switching to it during the test will cause the engine to stop as the spark is removed. This is another excellent sign that your aircraft engine should be serviced.
Automobiles, for whom engine reliability is not nearly as life-critical, rely on cheaper and more efficient battery-and-coil systems to drive all plugs. The battery and ignition coil system means that the starter motor isn't responsible for generating enough oomph to both turn the motor and generate enough power to fire the plugs, so the starter motor can be smaller. Also, weight is not nearly as much of a penalty on the car, so the battery can be larger; thus, in the event that your (single) alternator does fail, a car can actually be driven quite a ways solely on the contents of the battery. The magnetos give an aircraft a redundant system without having to double the weight of the heavy battery. The ignition coil (along with a distributor or electronic ignition system) is useful if you want to be able to tweak the ignition timing of the engine, as well; if the engine rotation itself is producing the spark, it's very difficult to get the ignition system to fire at a different time. However, this is most useful for engines that change their speed frequently, and airplane motors don't do this. Plus, it's another complex and fragile system whose loss can render the engine inoperable.
StuartO))) points out, quite correctly, that magnetos are also still used in small motors which are not used regularly or for long, such as in chainsaws and lawn mowers.