Fireworks were invented in China during the Tang Dynasty (around 9th century). Chinese alchemists accidentally discovered gunpowder while trying to create an elixir of immortality, and this led to the development of fireworks. India, Sri Lanka, and Pakistan were not the origin of this invention.