Maliks Muwatta Book 9, Hadith Number 80.

Section : How to Do the Prayer in General.

Yahya related to me from Malik from Nafi that Abdullah ibn Umar used to say, “Someone who only remembers that he has forgotten a prayer when he is praying the next prayer behind an imam, should pray the prayer he has forgotten after the imam has said the taslim, and then pray the other one again.”