Bulugh al-Maram 71
وَعَنْ أَبِي هُرَيْرَةَ - رضي الله عنه - قَالَ: قَالَ رَسُولُ اللَّهِ - صلى الله عليه وسلم: «إِذَا وَجَدَ أَحَدُكُمْ فِي بَطْنِهِ شَيْئًا, فَأَشْكَلَ عَلَيْهِ: أَخَرَجَ مِنْهُ شَيْءٌ, أَمْ لَا? فَلَا يَخْرُجَنَّ مِنَ الْمَسْجِدِ حَتَّى يَسْمَعَ صَوْتًا, أَوْ يَجِدَ رِيحًا». أَخْرَجَهُ مُسْلِمٌ.
From Abu Hurayrah, may Allah be pleased with him, who said: The Messenger of Allah ﷺ said: "When one of you feels something in his stomach and is unsure whether something has come out of him or not, he should not leave the mosque until he hears a sound or finds a smell." Reported by Muslim.