(a) Sayyiduna Ali (may Allah be pleased with him) said: Whoever, during the prayer, feels a disturbance in his stomach or the need to urinate should place his garment on his nose, go out and perform ablution, and not speak to anyone in the meantime; if he speaks, he should pray afresh.
(b) These narrations, if they are authentic, contain evidence that if one feels a disturbance in the prayer, it is permissible to leave the prayer before the ritual impurity (hadath) occurs, perform ablution and continue on the same prayer.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3387