On several occasions when masturbating, I've urinated before ejaculating, and I even urinated immediately after I had ejaculated once. I am sure that it isn't pre-cum. What is causing this? Is it dangerous or unhealthy? How can I prevent this from happening? Will it go away eventually?
In the drawing to the right, notice the bladder and the ejaculatory duct. Both structures have a tube leading off from them, going through the prostate and then out the urethra. When you are strongly sexually aroused, muscles in the prostate open the path to the ejaculatory duct while simultaneously closing the path from the bladder. When you ejaculate, the semen takes the path of least resistance and squirts out the end of your penis. When you are not sexually aroused, the path to the bladder is open and the path to the ejaculatory duct is closed off so that when you pee, the urine doesn't back up into the ejaculatory duct but flows out the penis.
Older men sometimes have problem with this switching muscle because their prostate has gotten enlarged, interfering with the operation of the muscle. Sometimes physical damage or even side-effects of a drug will interfere with the proper operation of this muscle. Problems can arise if semen ends up in the bladder or urine ends up in the ejaculatory duct. If this continues to happen, you need to mention it to your doctor so he can check and make sure it isn't something serious.
But in general, since you do have this problem, you can avoid it by first urinating before you masturbate. That will take the pressure off the muscle closing the path to the bladder. Perhaps with rest and time the muscle will grow stronger.