The caffeine in coffee raises the body’s level of dopamine, which causes pleasurable sensations that counteract pain. Caffeine also narrows swollen blood vessels in the brain that are associated with certain types of headaches, such as migraines. If you usually drink one cup of coffee a day, a second one may make you feel better when you get a headache.