The use of violence is explicitly forbidden in Islam in general. But only (exceptionally) in cases of self-defense in response to explicit aggression, when injustice was being perpetrated against the Muslim community in early Islamic history, then on a temporary basis permission was given to defend themselves. This principle is explained in the following verses:
Permission [to fight] is given to those against whom war is being wrongfully waged – and, verily, God has indeed the power to succor them – those who have been driven from their homelands against all right for no other reason than their saying, “Our Sustainer is God!” For, if God had not enabled people to defend themselves against one another, [all] monasteries and churches and synagogues and mosques – in which God’s name is abundantly extolled – would surely have been destroyed before now. [Qur’an 22:39-40]
The highest justification for a defensive war is for the purpose of defending religious freedom and human rights. This verse also acknowledges Christian and Jewish places of worship as equally worthy of defense because these are places in which “God’s name is abundantly extolled.”
All relevant authorities show that this is the earliest Qur’anic reference to the problem of war as such. It was revealed immediately after the Prophet Muhammad (s.a.w.s.) left Mecca for Medina. The principle of war in self-defense has been further elaborated in the following verses which were revealed about a year later:
And fight in God’s cause against those who wage war against you, but do not commit aggression – for, verily, God does not love aggressors. And slay them wherever you may come upon them, and drive them away from wherever they drove you away – for oppression (fitnah) is even worse than killing. [Qur’an 2: 190-191]
The phrase “slay them where you find them” obviously refers to a situation in which a community has already been attacked and is responding defensively. Thus war was permitted when it was defensive in nature. Thus, war in Islam only happened to repel the enemy’s threats, but stopped immediately after the enemy retreated.
Surah Tauba (Chapter Nine) is the most authoritative chapter on the concept of war in the Qur’an and is one that is abused by both extremist Muslims and those who allege that Islam is a violent religion. However, in verses four and seven of this chapter it is clearly stated that Muslims can only declare war with people who have broken their treaty with them or who have resorted to enmity first. It is also emphasized in this chapter that Muslims must stay loyal to their commitments and never break them, and this applies to all commitments and treaties, not merely to those with other Muslims. It is further stated that if they incline to peace, incline to it as well, and place your trust in God: indeed, He alone is all hearing, all knowing! [Qur’an 8:61]