I asked the Messenger of Allah ﷺ, "Which sin is greatest in the sight of Allah?"He answered, "That you set up a rival to Allah, when it is He who created you."I said, "That is indeed grave. Then which?"He said, "Then that you kill your child out of fear that he will eat with you."I asked, "Then which?"He replied, "Then that you commit adultery with your neighbor's wife."In another narration it adds, And Allah sent down confirmation of the Prophet's ﷺ words, "And those who do not invoke another god alongside Allah, nor kill the soul which Allah has forbidden except by right, nor commit adultery. Whoever does that will meet a penalty." [Furqan 25:68].
سألت رسول الله ﷺ أي الذنب أعظم عند الله؟ قال: أن تجعل الله ندا وهو خلقك قال: قلت له: إن ذلك لعظيم، قال: قلت: ثم أي؟ قال: ثم أن تقتل ولدك مخافة أن يطعم معك قال: قلت: ثم أي؟ قال: ثم أن تزاني حليلة جارك. زاد في رواية: وأنزل الله تصديق قول النبي ﷺ: {والذين لا يدعون مع الله إلها آخر ولا يقتلون النفس التي حرم الله إلا بالحق ولا يزنون ومن يفعل ذلك يلق أثاما} [الفرقان: ٦٨].
Bukhari narrated it in al-Adab (6001), and Muslim in al-Iman (86), both through the route of Mansur, from Abu Waail, from Amr bin Shurahbil, from Abdullah, who mentioned it. The wording given is Muslim's.