Praise be to Allah.
If an incident such as an earthquake or fire occurs whilst someone is praying, and he thinks it most likely that he will be harmed because of it, but if he interrupts his prayer he will be saved, then he is obliged to flee from it and to try to save himself, then he may complete his prayer, or he may interrupt his prayer, depending on the scale or nature of the incident. It is not permissible for him to stay where he is when he thinks it likely that he may die, otherwise he will be throwing himself into destruction. By the same token, he must interrupt his prayer in order to save others from destruction, such as in the case of drowning, fire or falling into a well.
The basic principle concerning that is the verse in which Allah, may He be exalted, says (interpretation of the meaning):
“and do not throw [yourselves] with your [own] hands into destruction. And do good; indeed, Allah loves the doers of good”
And the Prophet (blessings and peace of Allah be upon him) said: “There should be neither causing harm nor reciprocating harm.” Narrated by Ahmad and Ibn Maajah (2341); classed as saheeh by al-Albaani in Saheeh Ibn Maajah.
In Kashshaaf al-Qinaa‘ (1/380) it says: It is obligatory to push back a disbeliever whose life is protected because he is living under Muslim rule, or because of a truce or promise of safety, from wells and the like [lest he fall into them] and to protect him from a snake that is heading towards him, just as one would act to protect a Muslim in such cases, because the lives of both are protected according to Islamic law.
And it is obligatory to save one who is drowning and the like, such as one who is burning, and one should interrupt the prayer in order to do that, whether the prayer is obligatory or supererogatory (naafil). What appears to be the case is that the prayer should be interrupted even if the time remaining for it is short, because it is possible to make it up by offering the prayer later [qada’], unlike saving one who is drowning and the like [which must be done immediately and cannot be done later on].
If a person refuses to interrupt his prayer in order to save one who is drowning and the like, then he is sinning, although his prayer is still valid, like one who prays wearing a turban made of silk. End quote.
Ibn Rajab al-Hanbali (may Allah have mercy on him) said: Qataadah said: If his garment is stolen, he should chase the thief and leave his prayer. ‘Abd ar-Razzaaq narrated in his book from Ma‘mar, from al-Hasan and Qataadah, that they said concerning a man who is praying, and is worried that his mount may wander off, or that a wild animal is about to attack it: He should stop praying [and deal with the situation].
It was narrated from Ma‘mar that Qataadah said: I asked him: If a man is praying and he sees a child at a well and is afraid that the child may fall into it, should he stop praying?
He said: Yes.
I said: What if he sees a thief who is about to take his shoes?
He said: He should stop praying.
The view of Sufyaan is that if an escalating situation occurs when a man is praying, he should stop praying and deal with it. Narrated from him by al-Ma‘aafa. The same applies if he is afraid that a flash flood may carry off his flock or mount.
The view of Maalik is that if someone’s mount begins to wander off whilst he is praying, he may walk to it if it is still close by, in front of him or to his right or his left, and if it has gone too far, he may go and get it, and interrupt his prayer.
The view of our companions is that if he sees someone drowning or burning, or two children fighting and the like, and he is able to deal with the matter, then he should interrupt his prayer and deal with it.
Some of them limit that to naafil prayers, but the more correct view is that it applies both to obligatory prayers and others.
Ahmad said, regarding one who is holding on to someone who owes him money, and they start to pray, then that debtor runs away whilst he is praying: He should stop praying and go after him.
Ahmad also said: If he sees a child falling into a well, he should interrupt his prayer and rescue the child.
Some of our companions said: He should only interrupt his prayer if he needs to move a great deal in order to rescue him; if it will not take much movement, then that will not invalidate his prayer.
Abu Bakr said, concerning one who went out in pursuit of one who owed him money: He may come back and continue his prayer from where he left off. Al-Qaadi understood that as meaning that the movements involved were small.
It may be said that he feared for his wealth, so his actions will be forgiven, even if it involved a lot of movement.
End quote from Fath al-Baari by Ibn Rajab (9/336-337).
It is not permissible for one who fears that he himself may die, or that someone whose life is protected according to Islamic law whom he could save may die, to continue praying, and he is sinning by doing that. If he dies or is injured, then he is regarded as having thrown himself into destruction.
And Allah knows best.