Answer
Wa `alaykum as-salamu wa rahmatullahi wa barakatuh.
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
1- Ejaculation voids the fast if it is due to kissing, hugging, or masturbation, and the day must be made up for later.
2- If ejaculation is due to lustful looking at or sexual thoughts, then it does not void the fast.
Answering your question, Dr. Wael Shehab, PhD in Islamic Studies from Al-Azhar University and currently the Imam of the Downtown Toronto Masjid in Canada, states:
I would like to advise you to spare no efforts to get right of such a bad habit that may negatively affect you.
You should seize the chance of the blessed days of Ramadan to get rid of your bad habit. With patience, more involvement in good deeds, and resolve, you would be able to free your mind of such thoughts.
You may engage in reciting some adhkar (duaa), tasbeeh, or Quranic verses when you go to bed. You may listen to some good Quranic recitations or good songs.
You may busy yourself with reflections on good things such as the marvels of the world.
You may go through professional counselling for help too.
If you could get married, this will be of great help.
As for ejaculation while fasting because of thinking about sex, scholars have different views regarding ejaculation due to lustful looking or sexual thoughts. But, you should be careful as ejaculation due to masturbation breaks the fast.
In his well-know, Fiqh Al-Sunnah, late Sheikh Sayyed Sabiq says:
Ejaculation voids the fast even if it was just due to kissing, hugging, or masturbation, and the day must be made up for later. If ejaculation was due to lustful looking at or thinking about sex, then it is like having a wet dream during the day and it, therefore, does not void the fast nor is there any requirement on the person.
Similarly, ejaculation of seminal fluid (madhi) does not harm the fast in any way.”
Allah Almighty knows best.
Editor’s note: This fatwa is from Ask the Scholar’s archive and was originally published at an earlier date.