First, we need to make a distinction between the two main classes of painkillers, which are used for different situations and function via different mechanisms.
The first class is the narcotic opioid drugs. These are the heavy-duty drugs, like morphine and codeine, used to treat severe pain. They relieve pain in two ways: first by interfering with and blocking the transmission of pain signals to the brain, and then by working in the brain to alter the sensation of pain. These drugs neither find nor kill pain, but reduce and alter the user's perception of the pain. They're kind of like having an optimistic friend that says, "Hey man, everything will be cool. Nothing's wrong. Here, look at this shiny, distracting thing!"
The other class is the aspirin drugs, like paracetamol and ibuprofen. These are the over the counter drugs we reach for whenever we've got a headache or a sore back. Throughout history, people all over the world were using botanical remedies for pain. The ancient Egyptians used leaves from the myrtle bush, Europeans chewed on hunks of willow bark and Native Americans did the same with birch bark. In the nineteenth century, scientists isolated the chemical in all these plants that gave them their pain relieving properties: salicin (which is metabolized to salicylic acid when consumed). They also discovered that these chemicals produced the side effect of horrendous digestive problems (which answers that other burning question, "Why is that Native American in that old commercial crying?").
Eventually, a scientist at Bayer Pharmaceutical synthesized a less harmful derivative chemical, acetylsalicylic acid (ASA). Bayer dubbed it Aspirin and commercialized it. Hoffmann went on to develop a "non-addictive" substitute for morphine. The resulting product, heroin, was less successful than aspirin.
Despite its long history, we didn't discover how aspirin works until the early 1970s. Unlike narcotics, aspirin drugs are real workhorses that actually go to the source of pain and stop it. When cells are damaged, they produce large quantities of an enzyme called cyclooxygenase-2. This enzyme, in turn, produces chemicals called prostaglandins, which send pain signals to the brain. They also cause the area that has been damaged to release fluid from the blood to create a cushion so the damaged cells don't take any more of a beating. This cushion is the swelling and inflammation that goes along with our aches and pains. When we take aspirin, it dissolves in our stomachs and travels through the whole body via the bloodstream. Although it's everywhere, it only works its magic at the site of cell damage by binding to the cylooxygenase-2 enzymes and stopping them from prostaglandins. No more prostaglandins means no more pain signals. The cells at the damage site, of course, are still damaged, but we're left blissfully unaware.
This prostaglandin-stopping power is also why people take aspirin regularly to reduce the risk of heart attacks, since prostaglandins in the bloodstream can cause clotting. Additionally, aspirin reduces the production of thromboxane, a chemical that makes platelets, a type of blood cell, sticky. With aspirin in our systems, platelets make less thromboxane and are less likely to form a clot and block an artery.