As a general rule, Muslims should not harm other people, especially other Muslims. The only exception to this rule is due to the need for self-defense against aggression or to avert some greater evil, as stated in the following subsidiary legal maxim:

الضَّرَرُ الْأَشَدُّ يُزَالُ بِالضَّرَرِ الْأَخَفِّ

Greater harm can be removed by lesser harm.

Source: Sharḥ Majallat al-Aḥkām 1/54

The Prophet decreed this rule as a matter of law and ethics.

Ubaida ibn As-Samit reported: The Messenger of Allah, peace and blessings be upon him, issued a decree:

If you would be pleased to be safe and for your religion to be safe for you, then restrain your hands from harming the lives of people, restrain your tongues from harming their honor, and restrain your stomachs from consuming their wealth.

Shall I not tell you what distinguishes the best of you from the worst of you? The best of you are those from whom goodness is expected and people are safe from their evil. The worst of you are those from whom goodness is not expected and people are not safe from their evil.

In contrast, protecting people from harm is a virtuous deed in Islam, such that it can be a means of great reward in the Hereafter. Even a simple act such as removing thorns from the road is a good deed that leads to Paradise.

Abu Barza reported: I said, “O Messenger of Allah, teach me something that will benefit me.” The Messenger of Allah, peace and blessings be upon him, said:

In sum, one of the fundamental characteristics of Islam and a true Muslim is to protect people from harm and evil. The only case in which it is permitted to harm someone is if it is the only way to prevent an even greater harm and evil. We have to be sure we treat people well, refrain from harming them, and take steps to ensure harm is reduced from the environment and other people.