Abu Hurairah (may Allah be pleased with him) narrates that the Messenger of Allah (peace be upon him) said: "When any one of you feels something in his stomach and becomes doubtful whether anything has come out of him or not, he should not leave (the mosque) until he hears a sound or perceives a smell." This is the narration of Khalid bin Abdullah.
Related hadith on this topic