Repentance and redemption
The Babylonian Talmud: Sanhedrin 97:72
Rabbi Eliezer said: if the people of Israel repent, they will be redeemed; and if not, they will not be redeemed.
Rabbi Yehoshua said: True, if they do not repent they will not be redeemed. But the Almighty appoints for them a King whose decrees are harsh like Haman, and Israel then repents and returns to the straight and narrow.