One thing that people have to understand is that the octane number isn't the amount of octane present, it's the ratio of octane to heptane that provides a similar knock resistance.
Knocking or detonation occurs when the temperatures and pressures inside the cylinder get too high and part of the fuel mix auto-ignites, this then starts off a chain reaction where the shockwave of the ignited fuel sets off the fuel near to it, and it passes through the mix at the speed of sound burning everything.
Normal combustion is "deflagration" where a flame front passes through the mix in a controlled manner.
This is burning things by passing heat onto the nearest cool neighbours. With detonation, the remaining mix is just under the auto ignition temperature, and the shockwave pressure is enough to tip it the final amount.
If you lit the corner of a piece of paper, it would deflagrate by the flame slowly incresing in size and spreading.
Detonation of paper would be when the sheet burns from one side to the other at supersonic speed.
Back to the fuels, higher "octane rating" fuels can resist the pressures and temperatures better, which allows you to advance the ignition, and start the burn earlier.
The faster an engine turns, the less time you have to extract power out of the expending gasses. The speed at which they burn doesn't change much and you need to get the pressure up nice and high for when the piston is at between 13-16 degrees of crank rotation.
This can be thought of like pedalling a bike, if you push hard when the pedal is pointing directly up, you'll just balance and sit on the top.
The best leverage you'd get on a pedal would be when it's at 3 o'clock, but as it's a drawn out push, rather then a quick bang, you get the most useful "work" done when you aim for peak pressures around 14-ish degrees.
The spark will occur before the piston has even reached the top of the cylinder in preparation to get this peak pressure in the right spot, and the faster the engine turns, the earlier you need to start the burn to get it to land on the sweet spot.
When the octane rating is increased, you can start the burn earlier without fear of the mix exploding by itself when the pressures get high, and one way to increase the octane rating is to slow the speed of the burning
Aside from increasing the amounts of harder the ignite components in fuel, you can also get a couple more octane points by slowing the burn instead, and it's this slowing that can reduce power.
Most petrol fuels are blended in such a way to keep the flame front moving at the same speed, although there is quite a few places out on the net that are under the impression that octane number is directly proportional flame front speed.
There are infact some racing fuel blends that have very high octane numbers, and high flame front speeds.