In the name of Allah al-Rahman al-Rahim
Everything happens with the Divine Will (Iradah) and predestination of Allah (Most High). The will of the creation is created by Allah (Most High). Whatever Allah (Most High) has willed will happen and whatever Allah (Most High) has not willed will not happen.
Nothing is hidden from the Divine Knowledge of Allah (Most High) before the creation was in existence and He knows what they will do before they carry out those actions. The fate of everything in creation has been preordained by Allah (Most High).
“Say: Never will we be struck except by what Allah has decreed for us; He is our protector. Upon Allah let the believers rely.”
[Surah al-Tawbah, verse 51]
“With Him are the keys of the unseen; none knows them except Him. He knows what is on the land and in the sea. Not a leaf falls but that He knows it. No grain is there within the darkness of the earth and no moist or dry but that it is in a clear record.”
[Surah al Ana'am, verse 59]
“It is not [possible] for one to die except by permission of Allah at a decree determined. Whoever desires the reward of this world – We will give him thereof; and whoever desires the reward of the Hereafter – We will give him thereof; and we will reward the grateful.”
[Surah Aali I'mran, verse 145]
However, human beings are responsible for their actions, and will be accounted for their actions by Allah (Most High).
“The record [of deeds] will be placed [open], and you will see the criminals fearful of that within it, and they will say, “Oh, woe to us! What is this book that leaves nothing small or great except that it has enumerated it?” They will find what they did present [before them]. And your Lord does injustice to no one.”
[Surah al-Kahf, verse 49]
Allah knows best.
Answered by Shaykh Muhammad Asrar Rashid