אל תאמר בלבבך ... בצדקתי הביאני ה' לרשת את הארץ הזאת "Do not say in your heart ... it is on account of my righteousness that the L-rd brought me to inherit this land" (Debarim 9:4). Moshe Rabbenu, 'a"h, had previously cautioned the people not to think that their success against the kings of Canaan was on account of their strength and the might of their hand (8:17).
Now he cautions them not to think that it was on account of their righteousness either. Rather, it was on account of the wickedness of the other nations. In truth, the wickedness of the nations explains why they were defeated. What it does not explain, however, is why the Jewish people were chosen to inherit their land.
Moshe Rabbenu, 'a"h, tells them that the reason they are inheriting the land is on account of the fact that G-d made an oath to their forefathers to give it to them. Even though Israel transgressed, G-d still had to give them the land as an inheritance, because He made an oath and it could not be rescinded.
(See Ramban on the Torah, 8:17, 9:4)
Ramban, Nachmanides, Parashat Ekev, 'Ekeb, 'Eqeb