Well, the first question that I can ask you is if you ejaculated?
If not, then the answer to your problem is the common phenomenon called "blue balls" caused by a congestion of the testicles and related equipment when they get excited and then nothing happens. As a sidenote, it's not really good for your testicles to have that happen very often, as it can increase your risk of prostate cancer and other testicle-related problems. The best way to make "blue balls" go away is to ejaculate.
If you did ejaculate, then your problem is a less-common problem that happens on occasion. When you haven't ejaculated for a while, or even when you have a particularly strong orgasm, your testicles aren't used to it and feel kind of sore afterwards. The best thing I can liken it to is, perhaps, a charlie horse of the testicles. If this is your problem, then don't worry. It's not harmful and will go away quite soon. And, yes, the more you masturbate and ejaculate, the less likely this sort of thing will happen. Besides, masturbating is good for you!