Devarim9:18

וָאֶתְנַפַּל לִפְנֵי יְהוָה כָּרִאשֹׁנָה אַרְבָּעִים יוֹם וְאַרְבָּעִים לַיְלָה לֶחֶם לֹא אָכַלְתִּי וּמַיִם לֹא שָׁתִיתִי עַל כָּל־חַטַּאתְכֶם אֲשֶׁר חֲטָאתֶם לַעֲשׂוֹת הָרַע בְּעֵינֵי יְהוָה לְהַכְעִיסוֹ׃

And I fell down before the Eternal, as at the first, forty days and forty nights: I ate no bread and drank no water, because of all your sin which you had sinned, in doing what was evil in the eyes of the Eternal, to provoke Him.

Devarim 9:18

וָאֶתְנַפַּל לִפְנֵי יְהוָה

Devarim / Deuteronomy 9:18 · Pshat

Devarim 9:18

וָאֶתְנַפַּל לִפְנֵי יְהוָה כָּרִאשֹׁנָה אַרְבָּעִים יוֹם וְאַרְבָּעִים לַיְלָה לֶחֶם לֹא אָכַלְתִּי וּמַיִם לֹא שָׁתִיתִי עַל כָּל־חַטַּאתְכֶם אֲשֶׁר חֲטָאתֶם לַעֲשׂוֹת הָרַע בְּעֵינֵי יְהוָה לְהַכְעִיסוֹ׃

And I fell down before the Eternal, as at the first, forty days and forty nights: I ate no bread and drank no water, because of all your sin which you had sinned, in doing what was evil in the eyes of the Eternal, to provoke Him.

Pshat פְּשָׁט

Three times forty days

You hurt someone close to you. They said "it's fine", but you feel the hurt is still there. Moshe (Moses) pleaded for the people again and again, until the Eternal truly forgave them.

Rashi: Moshe was on the mountain three times for forty days. The middle forty days passed in anger and ended on the twenty-ninth of Av. The last ones, in goodwill, ended on Yom Kippur, and on that day the Eternal said with joy: "I have forgiven according to your word." That is why this day was set for forgiveness. Malbim: already the first time the Eternal relented of destroying the people, but the anger still remained, and He thought to punish them another way. Only after the second forty days of prayer did He listen to Moshe and become reconciled with them.

How Rashi and Malbim explain it

Rashi And I fell down before the Eternal, as at the first, forty days

As it is said: "And now I will go up to the Eternal, perhaps I can atone for your sin" (Shemot / Exodus 32:30). That time, when I went up, I stayed there forty days. They ended on the twenty-ninth of Av, for Moshe went up on the eighteenth of Tammuz. On that day the Holy One, blessed is He, was reconciled with Israel and said to Moshe: "Carve for yourself two tablets of stone" (Devarim / Deuteronomy 10:1). Moshe spent another forty days there, and they ended on Yom Kippur. On that day the Holy One, blessed is He, was reconciled with Israel with joy and said to Moshe: "I have forgiven according to your word" (Bamidbar / Numbers 14:20). That is why this day was set for pardon and forgiveness.

And how do we know that He was reconciled wholeheartedly? Of the forty days of the last tablets it is said: "And I stayed on the mountain, as in the first days" (Devarim / Deuteronomy 10:10). As the first days were in goodwill, so the last were in goodwill. So the middle ones were in anger.

Malbim And I fell down

This is proof of how great the sin was and how great the anger: I had to lie prostrate forty days and forty nights. This was either because of the greatness of the sin, of which it says: "because of all your sin", or because of the greatness of the anger, of which it says: "For I was afraid of the anger and the fury" (Devarim / Deuteronomy 9:19).

"And the Eternal listened to me": for the first time too, when the Eternal said to him: "Let Me be, and I will consume them", and Moshe prayed: "Why, Eternal, does Your anger blaze against Your people?", it is written: "And the Eternal relented of the evil that He had spoken of doing to His people" (Shemot / Exodus 32:10–14). But then the anger and the fury still remained, and He still thought to punish them another way, so that there would be no desecration of the Name, as He punished for the sin of the spies: to destroy them little by little. But through the prayer of the second forty days the Eternal listened to him and was reconciled with them. This is explained in chapter 10: then He said to Moshe "Carve for yourself two tablets of stone", and that is a sign that He had listened to his prayer.

Takeaway

Rashi on Shemot / Exodus 33:11 counts the same way: on the seventeenth of Tammuz the first tablets were broken, then came forty days of prayer, from the first day of the month of Elul another forty days on the mountain, and on the tenth of Tishrei, Yom Kippur, the Eternal said "I have forgiven according to your word" and gave Moshe the second tablets.
The words "I have forgiven according to your word" are said in the Torah after the sin of the spies (Bamidbar / Numbers 14:20). Rashi brings them as the answer Moshe received on Yom Kippur.
The spies Malbim speaks of brought a bad report about the land. The punishment did not come at once: the generation of the wilderness died over forty years, until all of them were gone (Bamidbar / Numbers 14:33–35).