The Prophet ﷺ said, "Satan comes to one of you during his prayer and intrudes between him and himself until he no longer knows whether he has added or omitted. When that happens, let him perform two prostrations before giving the salam, then give the salam."
حدثنا سفيان بن وكيع حدثنا يونس بن بكير حدثنا ابن إسحق حدثني الزهري عن أبي سلمة
أن النبي ﷺ قال إن الشيطان يأتي أحدكم في صلاته فيدخل بينه وبين نفسه حتى لا يدري زاد أو نقص فإذا كان ذلك فليسجد سجدتين قبل أن يسلم ثم يسلم
Sourcing hasanAbu Dawud recorded it in the Book of Prayer, in the chapter "One who says he should complete his prayer based on the stronger likelihood", hadith no. 1032, from the hadith of Ibn Ishaq with this wording. See also Sunan Abu Dawud, no. 1030, and elsewhere.