The term “Blue Balls” refers to a condition that can affect the testes, and is colloquial speech for epididymal hypertension. It’s thought that this can occur when getting sexually aroused for an extended period of time but don’t have an orgasm or ejaculation.
When getting aroused the body increases blood into the penis and testicles, and the veins that would carry that blood away from the area restrict so that the blood stays there to create and maintain an erection and swollen testicles.
Typically, after an orgasm and semen ejaculation or when one is no longer aroused the blood would flow out of the area. However, if arousal maintains for an extended period and no release follows, the extra blood can stay around.
This can create certain symptoms, such as mild scrotal pain, a feeling of heaviness of the scrotum, discomfort, and sometimes a weak faint bluish color of the testes. This bluish hue is due to the increased volume of blood in the area, and hence the name Blue Balls.
Mind that some men deliberately control their ejaculation and create a high level of sexual arousal for an extended period (either during masturbation or sexual intercourse). It’s a practice known as Edging (also known as Gooning), which is a form of Ejaculative Orgasm Control.
Anyway, the occurrence of Blue Balls is not a dangerous health situation. It will go away by itself, but to get rid of the discomforts quickly one can either ejaculate or try to engage in non-arousing activities such as taking a cold shower, doing exercise, focusing on work, and so on.