It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you feels something in his stomach, or is in doubt whether something has come out of it or not, he should not leave the mosque until he hears a sound or perceives a smell."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 571