Devarim (Deuteronomy): Eikev > Ch 9
Moses tells Israelites that G-d will drive out Anakim (giants) out of the land of Israel
Hear, O Israel: Today, you are crossing the Jordan to come in to possess nations greater and stronger than you, great cities, fortified up to the heavens. A great and tall people, the children of the 'Anakim, whom you know and of whom you have heard said, "Who can stand against the children of 'Anak?!" You shall know this day, that it is the Lord your G-d Who passes over before you as a consuming fire He will destroy them, and He will subdue them before you; and you shall drive out them and destroy them quickly, as the Lord spoke to you.
Moses tells Israelites that G-d grants them this land because of their forefathers, not because of righteousness, since Israelites have angered G-d in the desert on multiple occasions.
Do not say to yourself, when the Lord, your G-d, has repelled them from before you, saying, "Because of my righteousness, the Lord has brought me to possess this land," and [that] because of the wickedness of these nations, the Lord drives them out from before you. Not because of your righteousness or because of the honesty of your heart, do you come to possess their land, but because of the wickedness of these nations, the Lord your G-d drives them out from before you, and in order to establish the matter that the Lord swore to your forefathers, Abraham, Isaac, and Jacob.
Moses retells the story about Israelites making the golden calf while Moses was on Mt. Sinai, and how Moses shattered the first set of tablets and pleaded with G-d to spare the people
You shall know that, not because of your righteousness, the Lord, your G-d, gives you this land to possess it; for you are a stiffnecked people. Remember do not forget, how you angered the Lord, your G-d, in the desert; from the day that you went out of the land of Egypt, until you came to this place, you have been rebelling against the Lord. At Horeb, you angered the Lord, and the Lord was incensed with you to destroy you. When I ascended the mountain to receive the stone tablets, the tablets of the covenant which the Lord made with you, I remained on the mountain forty days and forty nights; I neither ate bread nor drank water; and the Lord gave me two stone tablets, inscribed by the finger of G-d, and on them was [inscribed] according to all the words that the Lord spoke with you on the mountain from the midst of the fire on the day of the assembly. And it came to pass at the end of forty days and forty nights, that the Lord gave me two stone tablets, the tablets of the covenant. And the Lord said to me, "Arise, descend quickly from here, for your people whom you have brought out of Egypt have become corrupt; they have quickly deviated from the way which I commanded them; they have made for themselves a molten image." And the Lord spoke to me [further], saying, "I have seen this people, and, behold, it is a stiffnecked people. Leave Me alone, and I will destroy them and obliterate their name from beneath the heavens, and I will make you into a nation mightier and more numerous than they." So I turned and came down from the mountain, and the mountain was burning with fire, and the two tablets of the covenant were on my two hands. And I saw, and behold, you had sinned against the Lord, your G-d; you had made yourselves a molten calf; you had deviated quickly from the way which the Lord had commanded you. So I grasped the two tablets, cast them out of my two hands, and shattered them before your eyes. And I fell down before the Lord as before, forty days and forty nights; I neither ate bread nor drank water, because of all your sins you had committed, by doing evil in the eyes of the Lord to anger Him. For I was frightened of the wrath and the fury that the Lord was angry with you to destroy you, and the Lord hearkened to me also at that time. And with Aaron, the Lord was very furious, to destroy him; so I prayed also for Aaron at that time. And I took your sin the calf, which you had made, and I burned it with fire, and I crushed it, grinding it well, until it was fine dust, and I cast its dust into the brook that descends from the mountain.
And at Tav'erah, and at Massah, and at Kivroth Hata'avah, you provoked the Lord to anger. And when the Lord sent you from Kadesh Barnea, saying, "Go up and possess the land I have given you," you defied the word of the Lord your G-d, and you did not believe Him, nor did you obey Him. You have been rebelling against the Lord since the day I became acquainted with you. So I fell down before the Lord the forty days and the forty nights that I had fallen down; because the Lord had said to destroy you. And I prayed to the Lord and said, "O Lord G-d, do not destroy Your people and Your inheritance, which You have redeemed in Your greatness, and which You have brought out of Egypt with mighty hand. Remember your servants, Abraham, Isaac and Jacob; do not turn to the stubbornness of this people, to their wickedness, or to their sin. Lest [the people of] the land from which you brought us out will say, 'Because of the Lord's inability to bring them to the land about which He spoke to them, and because of His hatred toward them, He has brought them out to slay them in the desert.' But they are Your people and Your inheritance, which You brought out with Your great strength and with Your outstretched arm."
And I fell down before the Lord, as before, forty days:
As it says, “And now I will go up to the Lord, perhaps I will atone [for the golden calf]” (Exod. 32:20). At that ascent, I stayed there forty days; consequently, these ended on the twenty-ninth of Av, since he [Moses] ascended on the eighteenth of Tammuz. On the same day, G-d was reconciled with Israel and He said to Moses, “Hew for yourself two tablets” (Exod. 34:1). He [Moses] remained there another forty days; consequently, these ended on Yom Kippur [the tenth of Tishri]. On that very day, the Holy One, blessed is He, was joyfully reconciled with Israel, and He said to Moses, “I have forgiven according to your words” (Num. 14:20). Therefore [Yom Kippur] was designated [as a day] for pardon and forgiveness. And from where do we know that [G-d] was reconciled [with Israel] in complete acceptance? Because it says referring to the forty [days] of the later tablets, “And I remained on the mountain as the first days” (Deut. 10:10). Just as the first [forty days] were with [G-d’s] good will, so too, the last [forty days] were with [G-d’s] good will. We may now deduce that the intermediate [forty days] were with [G-d’s] anger. — [Seder Olam , ch. 6]