Sahih Muslim 2652 c
Abu Huraira reported Allah's Messenger (ﷺ) as saying:
There was an argument between Adam and Moses (peace be upon both of them) in the presence of their Lord. Adam came the better of Moses. Moses said: Are you that Adam whom Allah created with His Hand and breathed into himHis sprit, and commanded angels to fall in prostration before him and He made you live in Paradise with comfort and ease. Then you caused the people to get down to the earth because of your lapse. Adam said: Are you that Moses whom Allah selected for His Messengership and for His conversation with him and conferred upon you the tablets, in which everything was clearly explained and granted you the audience in order to have confidential talk with you. What is your opinion, how long Torah would haye been written before I was created? Moses said: Forty years before. Adam said: Did you not see these words: Adam committed an error and he was enticed to (do so). He (Moses) said: Yes. Whereupon, he (Adam) said: Do you then blame me for an act which Allah had ordained for me forty years before He created me? Allah's Messenger (ﷺ) said: This is how Adam came the better of Moses.
حَدَّثَنَا إِسْحَاقُ بْنُ مُوسَى بْنِ عَبْدِ اللَّهِ بْنِ مُوسَى بْنِ عَبْدِ اللَّهِ بْنِ يَزِيدَ الأَنْصَارِيُّ،
 حَدَّثَنَا أَنَسُ بْنُ عِيَاضٍ، حَدَّثَنِي الْحَارِثُ بْنُ أَبِي ذُبَابٍ، عَنْ يَزِيدَ، - وَهُوَ ابْنُ هُرْمُزَ - وَعَبْدِ
 الرَّحْمَنِ الأَعْرَجِ قَالاَ سَمِعْنَا أَبَا هُرَيْرَةَ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ احْتَجَّ
 آدَمُ وَمُوسَى عَلَيْهِمَا السَّلاَمُ عِنْدَ رَبِّهِمَا فَحَجَّ آدَمُ مُوسَى قَالَ مُوسَى أَنْتَ آدَمُ الَّذِي خَلَقَكَ
 اللَّهُ بِيَدِهِ وَنَفَخَ فِيكَ مِنْ رُوحِهِ وَأَسْجَدَ لَكَ مَلاَئِكَتَهُ وَأَسْكَنَكَ فِي جَنَّتِهِ ثُمَّ أَهْبَطْتَ النَّاسَ
 بِخَطِيئَتِكَ إِلَى الأَرْضِ فَقَالَ آدَمُ أَنْتَ مُوسَى الَّذِي اصْطَفَاكَ اللَّهُ بِرِسَالَتِهِ وَبِكَلاَمِهِ وَأَعْطَاكَ
 الأَلْوَاحَ فِيهَا تِبْيَانُ كُلِّ شَىْءٍ وَقَرَّبَكَ نَجِيًّا فَبِكَمْ وَجَدْتَ اللَّهَ كَتَبَ التَّوْرَاةَ قَبْلَ أَنْ أُخْلَقَ
 قَالَ مُوسَى بِأَرْبَعِينَ عَامًا ‏.‏ قَالَ آدَمُ فَهَلْ وَجَدْتَ فِيهَا ‏{‏ وَعَصَى آدَمُ رَبَّهُ فَغَوَى‏}‏ قَالَ
 نَعَمْ ‏.‏ قَالَ أَفَتَلُومُنِي عَلَى أَنْ عَمِلْتُ عَمَلاً كَتَبَهُ اللَّهُ عَلَىَّ أَنْ أَعْمَلَهُ قَبْلَ أَنْ يَخْلُقَنِي بِأَرْبَعِينَ
 سَنَةً قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ فَحَجَّ آدَمُ مُوسَى ‏"‏ ‏.‏