The happy ending to Esther is the key to the whole story. It's what everyone's waiting for, the moment of the big turn-around. Haman and Mordecai change places. Haman hangs on the gallows he built for Mordecai and Mordecai becomes the valued counselor to the king that Haman had once been. At the same time, the Jews are saved from their impending genocide.
It's sort of like the movie Trading Places—except, um… okay, so it's actually not at all like that movie. It would be like that movie if Dan Akroyd had been trying to kill Eddie Murphy, but then was hoisted on his own petard. And the Jamie Lee Curtis character would need to be Esther… or something? (Anyway, with all these characters swapping their lots in life, there are certain slight plot similarities.)