This is one of the most intricate problems of religion. For if you look into the traditional arguments (Hadith) about this problem you will find them contradictory; such also being the case with arguments of reason. The contradiction in the arguments of the first kind is found in the Qur'an and the Hadith.
Part 3: Of Fate And Predestination; Opening sentence. - On the Harmony of Religions and Philosophy