The first reference to the Afikoman is the talmudic warning not to serve fancy desserts or go partying after partaking in the Passover meal (Epikomos).  Afikoman was what you were not supposed to do - go from party to party carousing. Eventually, however, afikoman became something you had to have - a piece of matzah that would be the final thing you ate at the completion of the meal. Originally, a piece of the Passover lamb was the last thing eaten. Over time, matzah came to represent the Paschal lamb and the Afikomen became a small piece of matzah. So matzah, which began the meal as The Bread of Affliction, is transformed by our recreation of the Exodus, into the Bread of Redemption.

haggadah Section: Tzafun