Do the bad things that happen in this universe happen by the will of Allah?
Question

Does everything that happens in this universe happen by the will of Allah? If that is the case then how can things that Allah does not like happen under Allah’s sovereignty and by His will?.
Praise be to Allah.and blessings and peace be upon the Messenger of Allah and his family and companions. 
You should understand, may Allah bless you, that some people have been misguided with regard to the issue of al-qadar (the divine will and decree), because they think that if Allah decrees that an action should happen, that means that He likes that thing, and this leads them to think that evil actions happen outside of the will of Allah. Thus they attribute weakness and incapability to Allah, when they say that nothing happens in His dominion that He does not want, and so He may will a thing and it does not happen – exalted be Allah far above what they say. In fact there is no connection between what Allah loves and wants in terms what is permissible and not permissible, and what He wills and decrees should happen in the universe. This may be explained further as follows: 
Firstly: 
In the Quran and Sunnah, the will and decree of Allah is divided into two categories: 
-1-
His universal (kawni) will and decree. Nothing happens outside of this will. The kaafir and the Muslim are equal under this will. Acts of worship and acts of disobedience all happen by the will and decree of Allah. 
For example, Allah says (interpretation of the meaning): 
“But when Allah wills a people’s punishment, there can be no turning back of it”
[al-Ra’d 13:11] 
“And whomsoever Allah wills to guide, He opens his heart to Islam; and whomsoever He wills to send astray, He makes his breast closed and constricted, as if he is climbing up to the sky”
[al-An’aam 6:125]
-2-  
His legislative (shar’i) will, which applies only to that which He loves and is pleased with. 
For example, Allah says (interpretation of the meaning): 
“Allah intends for you ease, and He does not want to make things difficult for you”
[al-Baqarah 2:185] 
“Allah wishes to accept your repentance”
[al-Nisa’ 4:27] 
“Allah does not want to place you in difficulty, but He wants to purify you”
[al-Maa'idah 5:6]
-3- 
The difference between the two wills. There are differences between the universal will of Allah and His legislative will, which distinguish each from the other. These differences include the following: 
1-The universal will has to do with that which Allah loves and is pleased with, and with that which He does not love and is not pleased with, whereas His legislative will has to do only with that which Allah loves and is pleased with.
2-By His universal will he may decree something not for its own sake, but to serve another purpose, such as the creation of Iblees, for example, and all evil things, because of which many things happen which Allah loves, such as repentance, striving and seeking forgiveness.
His legislative will has to do with that which He prescribes for its own sake, for Allah wants us to obey Him and He loves that, so He prescribes it and is pleased with it for its own sake.
3-His universal will must inevitably come to pass, such as the birth or death of a person, etc.
But His legislative will – such as Allah wanting everyone to believe – does not necessarily come to pass. It may happen or it may not. If it were inevitable that it should come pass then all of mankind would become Muslims.
4-His universal will has to do with the Oneness of Allah’s Lordship and the fact that He is the only Creator, whereas His legislative will has to do with His Divinity and Law.
5-His two wills come together in the case of one who obeys Him. The one who prays – for example – combines both, because prayer is beloved to Allah; He has enjoined it and He is pleased with it and loves it, so it is prescribed by His legislative will in that sense. But the fact that it happens indicates that Allah willed that it should happen, so it is decreed by His universal decree in that sense. Hence the two wills are combined in the case of one who obeys Allah.
His universal will is at work on its own in the case of the disbelief of the kaafir and the sin of the disobedient. The fact that these things happen indicates that Allah willed that they should happen, because nothing happens except by His will. But the fact that Allah does not love them and He is not pleased with them indicates that they happen by His universal will, not by His legislative will. 
His legislative will is at work on its own in the case of a kaafir who starts to believe, or a sinner who starts to obey Allah. These things are beloved to Allah so they come under His legislative will. The fact that they do not happen – even though Allah has enjoined them and loves them – indicates that they come under His legislative will only. 
These are some of the differences between the two wills. Whoever understands the difference between them will avoid many doubts that cause people to stumble and go astray. Whoever looks at people’s actions with this double-faceted understanding will have clear insight, but whoever looks at it on the basis of the universal will only, without the legislative will, or vice-versa, it will be as if he is one-eyed. 
-4- 
Everything that Allah does is good, wise and just.  
Allah does what He does for reasons that are known to Him; His slaves or some of them may know some of those reasons, or their limited minds may be unable to comprehend much of the divine wisdom behind things. General decrees may be for general reasons and universal mercy, such as sending Muhammad (peace and blessings of Allah be upon him), as Allah says (interpretation of the meaning): 
“And We have sent you (O Muhammad) not but as a mercy for the ‘Aalameen (mankind, jinn and all that exists)”
[al-Anbiya’ 21:107]
Ibn al-Qayyim (may Allah have mercy on him) said: Allah is Most Wise. He does not do anything in vain or for no purpose. This is indicated by His words and the words of His Messenger (peace and blessings of Allah be upon him). 
And Allah knows best. May Allah send blessings and peace upon His Prophet Muhammad and his family and companions. 
See A’laam al-Sunnah al-Manshoorah, 147; al-Qada’ wa’l-Qadar fi Daw’ al-Kitaab wa’l-Sunnah by Shaykh Dr. ‘Abd al-Rahmaan al-Mahmoud; al-Eemaan bi’l-Qada’ wa’l-Qadar by Shaykh Muhammad al-Hamd.