Background Though women can suffer from painful vasocongestion, it is more often a male complaint. However, vasocongestion isn't necessarily all that painful in most cases. Listen up: vasocongestion happens in everyone every time we become sexually and genitally aroused. Simply, the penis or vulva fills with blood, which is how erection occurs in the male and vulval and vaginal changes due to arousal in the female. When we orgasm and/or ejaculate, the swelling from vasocongestion subsides and goes away. But if we do not orgasm or ejaculate after sexual stimulation and arousal, vasocongestion sometimes sticks around for a bit, and can cause pain or discomfort.
For people who have a penis, the primary source of discomfort when arousal is not followed by ejaculation is due to vasocongestive pressure in the penis and testicles and surrounding areas as a whole. One of the urologists I talked to compared the phenomenon to how a tension headache happens: blood pressure is increased, but the blood vessels that the blood must flow through are constricted (this creates vasocongestion, which creates an erection by keeping the blood in the penis) by vascular tension as well as muscle tension. When high blood pressure and high blood volume meet narrowed blood vessels, a little like trying to force the flow of a kitchen faucet through a soda straw, it's uncomfortable and can be downright painful sometimes. It is important to note that "blue balls" isn't about a buildup of sperm, because sperm simply doesn't "build up" in that way. Even though the pain in men is often felt most profoundly in the testes (AKA "balls"), that's because that's where many of the genital sensory nerves are and not because of a build-up of semen.
Again, people with a vulva instead of a penis, too, can suffer from vasocongestion, and may feel pain in the vulva, uterus or general pelvic area as a result of it, though it is discussed far less often, perhaps in part because women don't realize it isn't something that just happens to men.
Advised Approach Vasocongestion is taken care of rather easily.
Orgasm (ejaculatory or nonejaculatory) -- either with a partner or through masturbation -- will make the pain and swelling go away. Alternately, letting the arousal simply fade out with rest or other nonsexual activity will also make vasocongestion go toodle-oo. In addition, a cold or warm compress or shower can be used, as can an analgesic like ibuprofen or aspirin to alleviate the pain, or some simple physical activity like running, walking or other sports.
Weapons Other than the above, there is no real treatment for vasocongestion because it is not a disease, virus or illness, but instead a mild, very temporary physical condition that takes care of itself, much like a sore muscle or a tired body. However, all too often, vasocongestion or "blue balls" is used as a weapon.
Having "blue balls" isn't something someone does "to" you, nor is it something which when it happens to you obligates another person to fix it. Sometimes one partner will tell another they have given them "blue balls" and that therefore, they must "give them" an orgasm or else they will curl up and die. This patently is not so, and as you know from other parts of this site, no one can "give" anyone an orgasm. When it comes to the physical side of things, a penis doesn't know the difference between a hand and a vagina (nor vice-versa), and so the person suffering from vasocongestion doesn't need anyone else to relieve it for them. They can either masturbate, or simply wait for the pain to subside, which it will do relatively quickly.
Level of Danger Vasocongestion causes no short or long-term physical harm, and it is not contagious or infectious. It's very annoying, but not dangerous.
However, persistent pain in the sexual organs or abdomen can be for may reasons, so if you find you have these sorts of symptoms outside of incidences in which you have been sexually aroused without orgasm, or that they're lasting for days, visit your doctor, urologist or gynecologist.
Protective measures No matter what the situation, no form of sex can guarantee orgasm every single time, and our partners may not always be interested in participating in sex to the point of orgasm. Because vasocongestion happens when we simply get aroused, there really is no avoiding it. However, to keep it from becoming painful, simply know what to do when it does become painful, and handle it in whichever way you are comfortable with -- masturbation, rest, an analgesic, et cetera -- when it does happen.