Infectious causes would be the most likely possibility. This can include epididymitis or prostatitis. Each of these disorders should be evaluated for.
Epididymitis should be evaluated for by a urinalysis and tests for STDs such as gonorrhea and chlamydia. A scrotal ultrasound can also be considered to evaluate for this.
Prostatitis should be examined for via a digital rectal exam - possibly extruding prostatic fluid for analysis. If negative, you may want to consider a transrectal ultrasound to evaluate whether an abscess is present.
Followup with your personal physician is essential.
This answer is not intended as and does not substitute for medical advice - the information presented is for patient education only. Please see your personal physician for further evaluation of your individual case.