Fentanyl is a prescription opioid used to treat severe pain, such as after surgery. It is also prescribed for cancer patients with chronic pain who have developed a tolerance to less powerful opioid drugs.