The sages explained: how he happened upon you - karcha - that is, he "cooled you off" (from the root kar) for the other nations of the world.
To what can this be compared? To a boiling basin which no one could enter. A worthless person came along and jumped into it. Even though he was scalded, he cooled it off for others.
Similarly, when Israel came out of Egypt, all of the nations of the world feared them, as the verse states: “Then the princes of Edom were confused... fear and trepidation fell upon them (Exodus, 5:15-16). But when Amalek came and engaged them in battle, though he was punished by their hands, he cooled them off, made them less awe-inspiring to the other nations of the world.
Before the sun of Abraham began to rise, the entire world was desolate. It was as if the light of the world had been extinguished and the world was destined to sink into an abyss of corruption, evil, and paganism. And then Abraham came and lit an ember. His children followed and fanned that ember into a mighty flame that gave light and warmth.
When Israel left Egypt, they did so through spectacular wonders and a miraculous revelation of the Divine Presence. All of Israel, all of Egypt, and all the peoples of the world realized that G‑d alone rules and there is none beside Him.
All existence waited expectantly for that exalted occasion when G‑d would descend to Mount Sinai and speak directly to man. Man's pride was about to be humbled and G‑d alone would remain exalted. The false gods were about to vanish. G‑d had revealed Himself to His entire people and designated them to be His emissaries to mankind, to illuminate a path for them. Would there still be a nation audacious enough to contend, Who is G‑d that I should listen to Him (Shemos 5:2)?
All Israel was prepared for this occasion, and they were also prepared to bring the peoples of the world close to Him, as will be in the End of Days. And Amalek, the wicked, came and ruined everything. He leaped into the fire a fire which all others feared, and was scalded, but he cooled the fire for everyone else. And now, what did the other nations contend? They said: "The battle continues.! We have only surrendered temporarily." The rectification of the world would again be postponed for many years until the End of Days.
And as for Israel, though they saw that Amalek had been scalded, they too found that their fire and the strength of their faith was cooled, and they began to complain and quarrel with G‑d. Who would have believed that there was a nation with the audacity to try to wage war with them after all that had transpired, yet Amalek came and did so!
The battle continues. Israel has not yet lost her fear of mortal man, replacing it with fear of G‑d's majesty and grandeur. Amalek attacked the weak elements. He instilled fear in the minds of those whose hands were slipping as they held the yoke of Divine responsibility, and he planted anxiety in the hearts of those who were strong.