Hi
Welcome to the MedHelp forum!
One simple explanation is sexual arousal that does not end in ejaculation can cause congestion in the sperm carrying tubes. This causes a dull aching sensation in the penis and testicle also called ‘blue balls’. Masturbation helps relieve this pain.
If you have been sexually active then get a STD panel done. If these two possibilities are ruled out then it could be phimosis where in a sexually aroused penis the foreskin becomes very tight causing pain. Please consult an urologist.
Take care!
There are many reasons you could be suffering this symptom. This may not be much help immediately, but I would suggest seeking an examination from a doctor. You really need to narrow down what it could be by having an examination rather than people speculating online in this case
Pain in the vas deferens can be caused by prolonged sexual abstinence or delaying ejaculation during sexual intercourse. There could be mild congestion in there. You may want to see a urologist to rule out prostratitis.