Testicular pain following masturbation can have multiple reasons.
1. One common explanation for the same is a condition commonly known as “blue balls”. This is scientifically due to something known as pelvic congestion. This can occur when a long period of sexual stimulation does not finish in ejaculation quickly enough. During stimulation phase of an sexual act, the blood vessels in the genitalia fill with blood. Ejaculation allows this buildup to release mostly; and the blood vessels return to their normal size. If orgasm is delayed, however, the blood remains for a longer period of time. This may leave a temporary sensation of heaviness, aching, or discomfort. Masturbating in one session for a long period of time or multiple ejaculations in a short period may also result in pelvic congestion. You can try breaking apart the stimulation into two shorter sessions instead with gap in between. This will allow you to have a shorter period of excitement prior to release, and may perhaps prevent pelvic congestion.
2. The pain may also be related to how one positions himself during masturbation. If the testicles move around too much, this motion can be the reason behind the discomfort. You may, consider a change in position or try cupping your testicles with your free hand as you are masturbating.
3. Epididymitis can also be a source of testicular pain following ejaculation. This is caused by inflammation in the epididymis (the tube behind each testicle that stores and delivers sperm). The most common cause of epididymitis is a bacterial infection that can be the result of a sexually transmitted infection (STI) or bacteria that live in the intestines. The infection can usually be cleared up by a dose of antibiotics.
Since antibiotics work best the sooner they are taken, so talk to your Urologist as soon as possible to find out if you have epididymitis or a different testicular condition.