All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
Leaving the obligatory prayer abruptly without a valid reason under the Islamic Sharee‘ah is impermissible according to the consensus of jurists. Leaving the prayer before finishing it without a Sharee‘ah-acceptable reason is considered a playful action that contradicts the sanctity of worship. It is forbidden for Muslims to invalidate acts of worship (with no valid excuse under the Islamic Sharee‘ah). Allaah The Exalted Says (what means): {O you who have believed, obey Allaah and obey the Messenger and do not invalidate your deeds.}[Quran 47:33]
As for leaving the prayer before finishing it for a valid reason under the Sharee‘ah, such as for killing a snake or the like, it is permissible since there is a command in this regard. (If a snake or harmful creature appears before the worshipper while performing the prayer, he should kill it.) Other valid reasons under the Sharee‘ah for leaving the prayer before finishing it include fear of losing valuable belongings, the need to relieve someone in distress, cautioning someone who is sleeping or inattentive person about a snake or something similar and other such reasons in which the benefits of leaving the prayer before finishing it outweigh (the harms of) invalidating it. This is the case with the obligatory prayers, given that leaving the prayer abruptly before finishing it, in case of its permissibility, is done by proclaiming the Tasleem or any other action that contradicts or invalidates the prayer such as excessive talk or movement, turning or looking around.
If the prayer was interrupted due to a Hadath (i.e. ritual impurity) which nullifies ablution, then the worshipper does not need to do anything to end the prayer. It has already been invalidated due to the lack of one of the due conditions of prayer (i.e. purification from the minor or major impurities).