Rambam devotes a full chapter to free will, asserting unequivocally that every human being has the power to choose good or evil — this is the pillar of Torah and prophecy. He then addresses the apparent contradiction with divine foreknowledge, arguing that God's knowledge is of an entirely different order than human knowledge and cannot be measured by the same categories.
רְשׁוּת לְכָל אָדָם נְתוּנָה. אִם רָצָה לְהַטּוֹת עַצְמוֹ לְדֶרֶךְ טוֹבָה וְלִהְיוֹת צַדִּיק הָרְשׁוּת בְּיָדוֹ. וְאִם רָצָה לְהַטּוֹת עַצְמוֹ לְדֶרֶךְ רָעָה וְלִהְיוֹת רָשָׁע הָרְשׁוּת בְּיָדוֹ. הוּא שֶׁכָּתוּב בַּתּוֹרָה (בראשית ג כב) "הֵן הָאָדָם הָיָה כְּאַחַד מִמֶּנּוּ לָדַעַת טוֹב וָרָע". כְּלוֹמַר הֵן מִין זֶה שֶׁל אָדָם הָיָה יָחִיד בָּעוֹלָם וְאֵין מִין שֵׁנִי דּוֹמֶה לוֹ בְּזֶה הָעִנְיָן שֶׁיְּהֵא הוּא מֵעַצְמוֹ בְּדַעְתּוֹ וּבְמַחֲשַׁבְתּוֹ יוֹדֵעַ הַטּוֹב וְהָרַע וְעוֹשֶׂה כָּל מַה שֶּׁהוּא חָפֵץ וְאֵין מִי שֶׁיְּעַכֵּב בְּיָדוֹ מִלַּעֲשׂוֹת הַטּוֹב אוֹ הָרַע. וְכֵיוָן שֶׁכֵּן הוּא פֶּן יִשְׁלַח יָדוֹ: אַל יַעֲבֹר בְּמַחֲשַׁבְתְּךָ דָּבָר זֶה שֶׁאוֹמְרִים טִפְּשֵׁי אֻמּוֹת הָעוֹלָם וְרֹב גָּלְמֵי בְּנֵי יִשְׂרָאֵל שֶׁהַקָּדוֹשׁ בָּרוּךְ הוּא גּוֹזֵר עַל הָאָדָם מִתְּחִלַּת בְּרִיָּתוֹ לִהְיוֹת צַדִּיק אוֹ רָשָׁע. אֵין הַדָּבָר כֵּן אֶלָּא כָּל אָדָם רָאוּי לוֹ לִהְיוֹת צַדִּיק כְּמשֶׁה רַבֵּנוּ אוֹ רָשָׁע כְּיָרָבְעָם אוֹ חָכָם אוֹ סָכָל אוֹ רַחֲמָן אוֹ אַכְזָרִי אוֹ כִּילַי אוֹ שׁוּעַ וְכֵן שְׁאָר כָּל הַדֵּעוֹת. וְאֵין לוֹ מִי שֶׁיִּכְפֵּהוּ וְלֹא גּוֹזֵר עָלָיו וְלֹא מִי שֶׁמּוֹשְׁכוֹ לְאֶחָד מִשְּׁנֵי הַדְּרָכִים אֶלָּא הוּא מֵעַצְמוֹ וּמִדַּעְתּוֹ נוֹטֶה לְאֵי זוֹ דֶּרֶךְ שֶׁיִּרְצֶה. הוּא שֶׁיִּרְמְיָהוּ אָמַר (איכה ג לח) "מִפִּי עֶלְיוֹן לֹא תֵצֵא הָרָעוֹת וְהַטּוֹב". כְּלוֹמַר אֵין הַבּוֹרֵא גּוֹזֵר עַל הָאָדָם לִהְיוֹת טוֹב וְלֹא לִהְיוֹת רַע. וְכֵיוָן שֶׁכֵּן הוּא נִמְצָא זֶה הַחוֹטֵא הוּא הִפְסִיד אֶת עַצְמוֹ. וּלְפִיכָךְ רָאוּי לוֹ לִבְכּוֹת וּלְקוֹנֵן עַל חֲטָאָיו וְעַל מַה שֶּׁעָשָׂה לְנַפְשׁוֹ וּגְמָלָהּ רָעָה. הוּא שֶׁכָּתוּב אַחֲרָיו (איכה ג לט) "מַה יִּתְאוֹנֵן אָדָם חָי" וְגוֹ'. וְחָזַר וְאָמַר הוֹאִיל וּרְשׁוּתֵנוּ בְּיָדֵינוּ וּמִדַּעְתֵּנוּ עָשִׂינוּ כָּל הָרָעוֹת רָאוּי לָנוּ לַחֲזֹר בִּתְשׁוּבָה וְלַעֲזֹב רִשְׁעֵנוּ שֶׁהָרְשׁוּת עַתָּה בְּיָדֵינוּ. הוּא שֶׁכָּתוּב אַחֲרָיו (איכה ג מ) "נַחְפְּשָׂה דְרָכֵינוּ וְנַחְקֹרָה וְנָשׁוּבָה" וְגוֹ': שֶׁמָּא תֹּאמַר וַהֲלֹא הַקָּדוֹשׁ בָּרוּךְ הוּא יוֹדֵעַ כָּל מַה שֶּׁיִּהְיֶה וְקֹדֶם שֶׁיִּהְיֶה יֵדַע שֶׁזֶּה יִהְיֶה צַדִּיק אוֹ רָשָׁע אוֹ לֹא יֵדַע. אִם יֵדַע שֶׁהוּא יִהְיֶה צַדִּיק אִי אֶפְשָׁר שֶׁלֹּא יִהְיֶה צַדִּיק וְאִם תֹּאמַר שֶׁיֵּדַע שֶׁיִּהְיֶה צַדִּיק וְאֶפְשָׁר שֶׁיִּהְיֶה רָשָׁע הֲרֵי לֹא יֵדַע הַדָּבָר עַל בֻּרְיוֹ. דַּע שֶׁתְּשׁוּבַת שְׁאֵלָה זוֹ אֲרֻכָּה מֵאֶרֶץ מִדָּה וּרְחָבָה מִנִּי יָם וְכַמָּה עִקָּרִים גְּדוֹלִים וַהֲרָרִים רָמִים תְּלוּיִים בָּהּ אֲבָל צָרִיךְ אַתָּה לֵידַע וּלְהָבִין בְּדָבָר זֶה שֶׁאֲנִי אוֹמֵר. כְּבָר בֵּאַרְנוּ בְּפֶרֶק שֵׁנִי מֵהִלְכוֹת יְסוֹדֵי הַתּוֹרָה שֶׁהַקָּדוֹשׁ בָּרוּךְ הוּא אֵינוֹ יוֹדֵעַ מִדֵּעָה שֶׁהִיא חוּץ מִמֶּנּוּ כִּבְנֵי אָדָם שֶׁהֵם וְדַעְתָּם שְׁנַיִם. אֶלָּא הוּא יִתְעַלֶּה שְׁמוֹ וְדַעְתּוֹ אֶחָד וְאֵין דַּעְתּוֹ שֶׁל אָדָם יְכוֹלָה לְהַשִּׂיג דָּבָר זֶה עַל בֻּרְיוֹ. וּכְשֵׁם שֶׁאֵין כֹּחַ בָּאָדָם לְהַשִּׂיג וְלִמְצֹא אֲמִתַּת הַבּוֹרֵא שֶׁנֶּאֱמַר (שמות לג כ) "כִּי לֹא יִרְאַנִי הָאָדָם וָחָי" כָּךְ אֵין כֹּחַ בָּאָדָם לְהַשִּׂיג וְלִמְצֹא דַּעְתּוֹ שֶׁל הַבּוֹרֵא. הוּא שֶׁהַנָּבִיא אָמַר (ישעיה נה ח) "כִּי לֹא מַחְשְׁבוֹתַי מַחְשְׁבוֹתֵיכֶם וְלֹא דַרְכֵיכֶם דְרָכָי". וְכֵיוָן שֶׁכֵּן הוּא אֵין בָּנוּ כֹּחַ לֵידַע הֵיאַךְ יֵדַע הַקָּדוֹשׁ בָּרוּךְ הוּא כָּל הַבְּרוּאִים וְהַמַּעֲשִׂים אֲבָל נֵדַע בְּלֹא סָפֵק שֶׁמַּעֲשֵׂה הָאָדָם בְּיַד הָאָדָם וְאֵין הַקָּדוֹשׁ בָּרוּךְ הוּא מוֹשְׁכוֹ וְלֹא גּוֹזֵר עָלָיו לַעֲשׂוֹת כָּךְ. וְלֹא מִפְּנֵי קַבָּלַת הַדָּת בִּלְבַד נוֹדַע דָּבָר זֶה אֶלָּא בִּרְאָיוֹת בְּרוּרוֹת מִדִּבְרֵי הַחָכְמָה. וּמִפְּנֵי זֶה נֶאֱמַר בַּנְּבוּאָה שֶׁדָּנִין אֶת הָאָדָם עַל מַעֲשָׂיו כְּפִי מַעֲשָׂיו אִם טוֹב וְאִם רַע וְזֶה הוּא הָעִקָּר שֶׁכָּל דִּבְרֵי הַנְּבוּאָה תְּלוּיִין בּוֹ:
Free will is granted to all men. If one desires to turn himself to the path of good and be righteous, the choice is his. Should he desire to turn to the path of evil and be wicked, the choice is his. This is [the intent of] the Torah's statement (Genesis 3:22 : "Behold, man has become unique as ourselves, knowing good and evil," i.e., the human species became singular in the world with no other species resembling it in the following quality: that man can, on his own initiative, with his knowledge and thought, know good and evil, and do what he desires. There is no one who can prevent him from doing good or bad. Accordingly, [there was a need to drive him from the Garden of Eden,] "lest he stretch out his hand [and take from the tree of life]." A person should not entertain the thesis held by the fools among the gentiles and the majority of the undeveloped among Israel that, at the time of a man's creation, The Holy One, blessed be He, decrees whether he will be righteous or wicked. This is untrue. Each person is fit to be righteous like Moses, our teacher, or wicked, like Jeroboam. [Similarly,] he may be wise or foolish, merciful or cruel, miserly or generous, or [acquire] any other character traits. There is no one who compels him, sentences him, or leads him towards either of these two paths. Rather, he, on his own initiative and decision, tends to the path he chooses. This was [implied by the prophet,] Jeremiah who stated [Eichah 3:38: "From the mouth of the Most High, neither evil or good come forth." The Creator does not decree that a person should be good and refrain from being evil. Accordingly, it is the sinner, himself, who causes his own loss. Therefore, it is proper for a person to cry and mourn for his sins and for what he has done to his soul, the evil consequences, he brought upon it. This is implied by the following verse [ibid.:39]: "Of what should a living man be aggrieved? [A man of his sins.]" [The prophet] continues explaining, since free choice is in our hands and our own decision [is what prompts us to] commit all these wrongs, it is proper for us to repent and abandon our wickedness, for this choice is presently in our hand. This is implied by the following verse [ibid.:40]: "Let us search and examine our ways and return [to God]." One might ask: Since The Holy One, blessed be He, knows everything that will occur before it comes to pass, does He or does He not know whether a person will be righteous or wicked? If He knows that he will be righteous, [it appears] impossible for him not to be righteous. However, if one would say that despite His knowledge that he would be righteous, it is possible for him to be wicked, then His knowledge would be incomplete. Know that the resolution to this question [can be described as]: "Its measure is longer than the earth and broader than the sea." Many great and fundamental principles and lofty concepts are dependent upon it. However, the statements that I will make must be known and understood [as a basis for the comprehension of this matter]. As explained in the second chapter of Hilchot Yesodei HaTorah, The Holy One, blessed be He, does not know with a knowledge that is external from Him as do men, whose knowledge and selves are two [different entities]. Rather, He, may His name be praised, and His knowledge are one. Human knowledge cannot comprehend this concept in its entirety for just as it is beyond the potential of man to comprehend and conceive the essential nature of the Creator, as [Exodus 33:20] states: "No man will perceive, Me and live," so, too, it is beyond man's potential to comprehend and conceive the Creator's knowledge. This was the intent of the prophet's [Isaiah 55:8] statements: "For My thoughts are not your thoughts, nor your ways, My ways." Accordingly, we do not have the potential to conceive how The Holy One, blessed be He, knows all the creations and their deeds. However, this is known without any doubt: That man's actions are in his [own] hands and The Holy One, blessed be He, does not lead him [in a particular direction] or decree that he do anything. This matter is known, not only as a tradition of faith, but also, through clear proofs from the words of wisdom. Consequently, the prophets taught that a person is judged for his deeds, according to his deeds - whether good or bad. This is a fundamental principle on which is dependent all the words of prophecy.