(a) Sayyiduna Abu Hurayrah (may Allah be pleased with him) narrates that the Messenger of Allah (peace and blessings be upon him) said: "When one of you, during the prayer, feels a movement in his backside and is not certain whether his ablution has been broken, he should not break off his prayer until he hears a sound or notices a smell."
(b) This hadith provides evidence that when he hears a sound or notices a smell, he should break off the prayer. In this there is no difference between its happening deliberately, by forgetfulness, or involuntarily. And Allah knows best.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3376