Is there a drug to decrease sexual desire or prevent it?
Are there therapies to eliminate the habit of frequent masturbation, if one were to want to postpone sexual behaviors until a future relationship?
Sexual function is human biology. It is complex with aspects that are psychological + neurological + hormonal + vascular + etc. It's all interwoven.
Therefore, beyond chemical castration* (which as mentioned above is a harsh and drastic measure), the answer is no - at least not reliably, as decreased libido is only a potential side effect of some medications. Some examples include antipsychotics, antiepileptics, antihypertensives. Most adverse sexual side effects of medications are actually just physical, such as inability to orgasm or have a full erection - WITHOUT decreasing desire. Therefore they are not clinically indicated for intentionally decreasing libido. Even if you found someone to prescribe it, you would have to then deal with the unwanted effects of those medications' primary mechanism of action, and other potential side effects. Also, as a correction to your comment, Viagra doesn't increase sex drive, it increases erectile tumescence with arousal.
I do not have a formal reference for the below, it is from a lecture on sexual health by a faculty clinical psychologist:
A person CAN address the psychological aspects of sexual behaviors that they find distressing. The PsyD pointed out that for those who feel distress about masturbation behaviors, including in relationship settings, it is often not the act of masturbation that yields distress, it is what the person engages in during the act - e.g. pornography or ego-dystonic fantasies - and those are alterable behaviors. This is actually a common issue that psychologists/sex therapists see and know how to address. I advise seeking professional guidance for approaching this in a psychologically healthy way, as distress over sexuality can adversely impact healthy future sexual relationships.
*This Wikipedia explanation is actually better than other medical sites I found that aren't behind pay walls