I asked, "Messenger of Allah, which sin is the greatest?"He replied, "That you set up a rival to Allah, when it is He who created you."I asked, "Then what?"He said, "That you kill your child out of fear that he will eat with you."I asked, "Then what?"He said, "That you commit adultery with your neighbor's wife."
أخبرنا محمد بن بشار قال حدثنا عبد الرحمن قال حدثنا سفيان عن واصل عن أبي وائل عن عمرو بن شرحبيل
قلت يا رسول الله أي الذنب أعظم قال أن تجعل لله ندا وهو خلقك قلت ثم ماذا قال أن تقتل ولدك خشية أن يطعم معك قلت ثم ماذا قال أن تزاني بحليلة جارك
Bukhari transmitted it in the tafsir section, chapter "His saying, 'And those who do not invoke another deity along with Allah...'" etc, hadith no. 4761, from the hadith of Sufyan Thawri. Muslim transmitted it in the book of faith, chapter explaining that shirk is the worst of sins and stating the greatest sin after it, hadith no. 86, from the hadith of Shaqiq Abu Waail, with the same wording. It is also found in Al-Kubra, hadith no. 3476.