What is the Difference between mogas and avgas?
Chemically speaking, The difference in the fuels is the inclusion of lead-based additives that increase the Octane rating of the fuel, which are otherwise banned for use in other settings due to the negative effect on air quality. The other common use of leaded fuels I can think of is in auto racing, which also doesn't particularly prioritise air quality. Unleaded high-octane fuels do exist for aircraft engines, but those engines have to be certified to use those fuels, a long and expensive process. This is why they are less common. 

Octane rating itself measures how resistant the fuel is to detonation.

Engines run at a specific level of compression. Simplistically, More compression produces more power, which is important in smaller piston engines. But having too high a compression ratio causes the mixture in the cylinder to detonate on it's own before the proper point in the timing cycle where it should be ignited by the spark plug. This is called 'knocking'. 

In the best case, the result is increased fuel consumption as the ECU (ironically) throws more fuel into the mixture to reduce the possibility of detonation (at least in fuel-injected car engines this the case). In the worst case, the result is damage to the engine as uncontrolled detonation can put large unwanted loads on the crankshaft and the con-rods. Power output will be reduced in any case, which can be a massive issue for heavily laden aircraft attempting to climb in high or hot conditions.