Thanks for your query.Based on the facts that you have posted it appears that you have developed infection of the glans penis
and terminal urethra
mostly due to vigorous and rough handling of penis while masturbating.
Please take anti inflammatory medications along eith antibiotics .
till it gets cured completely and take precautions like cleaning and washing the the genitals before masturbating and using some lubricant.