Physicians may prescribe opioids for pain from: A procedure, such as surgery or dental work. An injury or accident. A chronic, or long-lasting, condition that causes pain. Cancer. Illness at the end of life.7