Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) said: "Forgetfulness is when one stands where he should sit, or sits where he should stand, or gives the salam after two rak'ahs. So, on finishing his prayer, he should perform two prostrations while sitting, recite the tashahhud in them, and give the salam."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3854