Imagine riding your motor bike from plain ground to an uphill path, initially it climbs the road in top gear. Then gradually the bike begins to slow down and the sound from the 100cc petrol engine begins to change. Still if you dont shift the gears the engine will stall, however long before the engine stalls you hear a distinct ringing sound (clanking metallic sound) from the engine (the sound is almost same for all petrol engine models). How is this sound produced. Is it from the valves?
Spark knock, or pre-detonation. It can happen when the timing is too far advanced, the octane rating of the fuel is too low, the air/fuel mixture is off which happens when you are lugging the engine (just as you described), see Wikipedia for details and more causes
The fuel-air charge is meant to be ignited by the spark plug only, and at a precise time in the piston's stroke cycle. The peak of the combustion process no longer occurs at the optimum moment for the four-stroke cycle. The shock wave creates the characteristic metallic "pinging" sound, and cylinder pressure increases dramatically. Effects of engine knocking range from inconsequential to completely destructive.
A different portion of the article that @Larry cites may make the acoustics a bit more clear:
When unburned fuel/air mixture beyond the boundary of the flame front is subjected to a combination of heat and pressure for a certain duration (beyond the delay period of the fuel used), detonation may occur. Detonation is characterized by an instantaneous, explosive ignition of at least one pocket of fuel/air mixture outside of the flame front. A local shockwave is created around each pocket and the cylinder pressure may rise sharply beyond its design limits.
This shockwave will impact the inner walls of the cylinders (and the valves). While that impact might not make a distinctly metallic sound itself, the entire cylinder and engine block is going to act like a resonance chamber. It's going to ring (or clank) like a very large oddly shaped bell.
You can simulate the same effect: hit a tuning fork with a rubber mallet. The tuning fork will ring even though you'd think that such a dull impact wouldn't make a clean tone.