I hope that you can tell me the right way to deal with this.
The Shaytaan is keen to corrupt the Muslim’s worship by means of waswaas, but the Muslim can ward off these tricks of the shaytaan by seeking refuge in Allaah, may He be exalted, from his evil, and learning the rulings of Islam and acquiring knowledge of fiqh. If he starts to doubt how many rak’ahs he has done during prayer, he should proceed on the basis of the smaller number and do the prostration of forgetfulness before saying the salaam. If he is not sure whether he divorced his wife or not, the basic principle is that he did not divorce her. If he is not sure whether there is any impurity (najaasah) on his body or clothes or not, the basic principle is that his body and clothes are pure, and so on.
These rulings apply to cases of doubt that do not stem from waswaas. If the doubt is caused by waswaas, then he should not pay attention to anything that the shaytaan casts into his mind, and there is no other solution but to seek refuge with Allaah from the Shaytaan and ignore this waswaas, and not pay any attention to it. Similarly, after doing wudoo’ and praying, if he feels uncertain about them, he should not pay any attention to that uncertainty.
If this waswaas is not warded off by seeking refuge with Allaah, and it overwhelms the Muslim until he says or does something without realizing, that is compulsive waswaas (al-waswaas al-qahri). This is a kind of sickness and he should seek treatment for it by means of ruqyah from the Qur'aan and Sunnah as prescribed in Islam, and permissible medicines. There is no reason why he should not go to a Muslim doctor whose religious commitment and knowledge of Islam can be trusted.
If this person who is affected by waswaas experiences physical movements that he cannot control or he says things that he cannot stop himself saying, then there is no sin on him and he is excused according to Islam, because in that case he has been burdened with something that he cannot bear, so he is excused because Allaah says (interpretation of the meaning):
“Allaah burdens not a person beyond his scope”
“So keep your duty to Allaah and fear Him as much as you can”
In the answer to question no. 10160 we have quoted the words of Shaykh Muhammad ibn Saalih al-‘Uthaymeen (may Allaah have mercy on him):
Similarly, if there crosses his mind any thought of impugning Allaah (may He be exalted) or impugning the Qur'aan or other kinds of kufr, he should not pay any attention to it, and it will not harm him, and even if we assume that he says such things involuntarily, there will be no sin on him. End quote.
For more information on your situation and on how to treat it by means of ruqyahs prescribed in Islam and adhkaar narrated from the Prophet (peace and blessings of Allaah be upon him), please see the following questions: 39684, 10160, 59931, 62839, 25778 and 12315. These are of benefit for those who are affected by waswaas and we hope that you will benefit from them. We ask Allaah to heal you and make you well.
And Allaah knows best.