"And Joshua weakened Amalek" (Exodus 17:13). Rabbi Joshua says: he went down and cut off the heads of the mighty men with him who stood in the battle ranks. Rabbi Elazar of Modi'in explains it as a notarikon [acronym-reading]: "and he was made to writhe, and he trembled, and he was broken." "Amalek" - according to its plain meaning. "And" - these are his wife and his sons. "His people" - these are the forces with him. And when it says "and," these are the forces with his sons. "With the edge of the sword." Rabbi [Judah] says: he did not disfigure them, but judged them with mercy. Rabbi Elazar says: "with the edge of the sword" - why is it said? We learn that this war was only by the mouth of the Almighty. Others say: this verse was fulfilled regarding them, "Therefore, as I live, says the Lord GOD, I will make you blood, and blood shall pursue you" (Ezekiel 35:6). "And Joshua weakened." Our Rabbis say: he cast lots upon them, as you say, "they cast lots [chalashim] for the portions." Four names are given to the lot: chalash, pur, goral, chevel; and by all of them the sons of Esau were stricken. By chalash Amalek was stricken, as it is said, "And Joshua weakened [vayachalosh]." By goral and by pur Haman was stricken, as it is said, "he cast pur, that is, the lot" (Esther 3:7). By chevel the fourth kingdom is destined to be stricken, as it is said, "the pangs [chevlei] of a woman in labor shall come upon him" (Hosea 13:13).
How Joshua Weakened Amalek and the Four Names of the Lot
Yalkut Shimoni on Torah 265:4
(שמות יז יג) וַיַּחֲלֹשׁ יְהוֹשֻׁעַ. רַבִּי יְהוֹשֻׁעַ אוֹמֵר, יָרַד וְחָתַךְ רָאשֵׁי גִבּוֹרִים שֶׁעִמּוֹ הָעוֹמְדִים בְּשׁוּרוֹת הַמִּלְחָמָה, רַבִּי אֶלְעָזָר הַמּוֹדָעִי אוֹמֵר, בּוֹ לְשׁוֹן נוֹטְרִיקוֹן, וַיִּחֶל וַיִּזַע וַיִּשָּׁבֵר, עֲמָלֵק, כְּמַשְׁמָעוֹ. וְאֶת, אֵלּוּ אִשְׁתּוֹ וּבָנָיו, עַמּוֹ, אֵלּוּ חֲיָלוֹת שֶׁעִמּוֹ. וּכְשֶׁהוּא אוֹמֵר וְאֶת, אֵלּוּ חַיָּלִים שֶׁעִם בָּנָיו. לְפִי חָרֶב. רַבִּי אוֹמֵר, לֹא נִוְּולָם אֶלָּא דָּנוּם בְּרַחֲמִים, רַבִּי אֶלְעָזָר אוֹמֵר, לְפִי חָרֶב, לָמָּה נֶאֱמַר, לָמַדְנוּ שֶׁהַמִּלְחָמָה הַזּאֹת לֹא הָיְתָה אֶלָּא עַל פִּי הַגְּבוּרָה. אֲחֵרִים אוֹמְרִים נִתְקַיֵּים עֲלֵיהֶם הַמִּקְרָא הַזֶּה, (יחזקאל לה, ו) "לָכֵן חַי אֲנִי נְאֻם ה' (צְבָאוֹת) [אֱלֹהִים] כִּי לְדָם אֶעֶשְׂךָ וְדָם יִרְדָּפֶךָ". וַיַּחֲלֹשׁ יְהוֹשֻׁעַ. רַבּוֹתֵינוּ אוֹמְרִים, הִפִּיל עֲלֵיהֶן גּוֹרָלוֹת, כְּמַּה דְּאַתְּ אָמֵר מְטִילִין חַלָשִׁים עַל הַמָּנוֹת. אַרְבַּע שֵׁמוֹת נִקְרְאוּ לַגּוֹרָל חֲלָּשׁ, פּוּר, גּוֹרָל, חֶבֶל, וּבְכוּלָּן לָקוּ בְּנֵי עֵשָׂו. בְּחַלָּשׁ לָקָה עֲמָלֵק, שֶׁנֶּאֱמַר וַיַּחֲלֹשׁ יְהוֹשֻׁעַ. בְּגּוֹרָל וּבְפּוּר לָקָה הָמָן, שֶׁנֶּאֱמַר (אסתר ג, ז) "הִפִּיל פּוּר הוּא הַגּוֹרָל". בְּחֶבֶל עָתִיד לִלְקוֹת מַלְכוּת רְבִיעִית, שֶׁנֶּאֱמַר "חַבְלֵי יוֹלֵדָה יָבֹאוּ לוֹ".