There once were small but terrible monsters, called shānxiāo 山魈, who lived in the forests on the side of mountains in western China. They were naked and lived on raw shrimps and crabs from the mountain streams. They used to come forth and steal salt from human communities in order to season their food. Sometimes they would steal other things as well.
Fortunately, they were afraid of fires and of loud noises. When they were near, people would light fires in their courtyards, and throw in bamboo so that it would make loud bangs as it burned. This was called bàozhú 爆竹, "bursting bamboo." The Shānxiāo would take fright and flee, leaving people in peace.
In Sòng 宋 dynasty times (period 15, 900s to 1200s AD) gunpowder was invented, and it was possible to make paper rolls containing gunpowder that would explode with an even greater sound. These were properly called bàozhàng 爆仗 ("bursting weapons"), but even today lots of people still say bàozhú, in memory of the original exploding bamboo that frightened away the shānxiāo.
And of course, everybody assumes that all sorts of evil forces, and not just shānxiāo, are frightened by firecrackers.
Well, anyway, we all hope that's true.