I asked, "Messenger of Allah, which sin is the greatest?"He replied, "That you set up a rival to Allah, when He is the One 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."Then Allah revealed a confirmation of what the Prophet ﷺ had said, "And those who do not invoke another god alongside Allah, nor kill the soul which Allah has forbidden except by right, nor commit adultery" [Furqan 25:68].
حدثنا محمد بن كثير أخبرنا سفيان عن منصور عن أبي وائل عن عمرو بن شرحبيل
قلت يا رسول الله أي الذنب أعظم قال أن تجعل لله ندا وهو خلقك قال فقلت ثم أي قال أن تقتل ولدك مخافة أن يأكل معك قال قلت ثم أي قال أن تزاني حليلة جارك قال وأنزل الله تعالى تصديق قول النبي ﷺ {والذين لا يدعون مع الله إلها آخر ولا يقتلون النفس التي حرم الله إلا بالحق ولا يزنون} الآية
Bukhari reported it in the Book of Manners, chapter on killing one's child for fear that he might eat, hadith 6001, from Muhammad bin Kathir, and Muslim in the Book of Faith, chapter clarifying that shirk is the worst of sins and explaining the greatest sins after it, hadith 141/86, both narrated from the hadith of Mansur, with the same chain.