The matza and maror must be eaten by midnight (the midpoint of the night, regardless of the time on the clock), and le-khatḥila, even the afikoman should be eaten before midnight. One who did not manage to eat the matza and maror before midnight should eat them after midnight without a berakha.
The basis for this law lies in a dispute between two Sages of the Mishna, R. Elazar b. Azarya and R. Akiva. According to R. Elazar b. Azarya, the Paschal sacrifice could be eaten only until midnight, and no later, because it was at midnight that the firstborns of Egypt were struck down, and the Egyptians began frantically trying to send the Israelites out of Egypt. According to R. Akiva, the matza may be eaten all night, until dawn, because it was at this time that the Israelites hurried to leave Egypt (Pesaḥim 120b).
From a spiritual perspective, we must explain that the offering and eating of the Paschal sacrifice revealed the unique quality of Israel, and this therefore constituted a preparation for the redemption. Accordingly, the meat of the korban Pesaḥ is eaten each year until the time of the redemption’s onset. The question is: Which phase of redemption determines the time to stop eating the Paschal sacrifice? According to R. Elazar b. Azarya, the redemption started at midnight, when the firstborns of Egypt were struck down, for it was then that Egyptians’ power was broken and they could no longer enslave us. Therefore, the Paschal sacrifice is eaten until midnight. However, according to R. Akiva, the complete redemption did not arrive until morning, when we went forth to freedom. Therefore, the entire night is a preparation for redemption, and it follows that one may eat the meat of the korban Pesaḥ all night.
Let us now return to the halakha. The time for eating the Paschal sacrifice also determines the time for eating matza and maror, because matza and maror were eaten together with the Paschal sacrifice, as it is stated, “They shall eat it with matzot and merorim” (Bamidbar 9:11). It follows that the time for eating matza is the same as the time for eating the Paschal sacrifice. The afikoman, which is eaten in commemoration of the korban Pesaḥ, must also be eaten at a time that is appropriate for eating the Paschal sacrifice.
Leading Rishonim disagree about which opinion to follow in practice. According to Rambam and Itur, the halakha follows R. Akiva, because, as a rule, we follow R. Akiva whenever he takes issue with one of his contemporaries. Thus, the korban Pesaḥ may be eaten throughout the entire night, and by extension so can matza, maror, and the afikoman. On the other hand, Rabbeinu Ḥananel and Rosh maintain that because the Mishna, in several places, states without dissent that the time for eating the korban Pesaḥ is until midnight, we may conclude that R. Yehuda Ha-Nasi, who compiled the Mishna, rules that on this issue the halakha follows R. Elazar b. Azarya.
Since this issue is subject to dispute, a kezayit of matza must be eaten before midnight, because according to those who maintain that the Paschal sacrifice may be eaten until midnight, eating it after midnight fails to fulfill the Torah commandment. Since the destruction of the Temple, maror has been a rabbinic enactment, and although we generally follow the lenient opinion with regard to rabbinic laws, maror must nevertheless be eaten before midnight since we recite a berakha over it. If circumstances prevented one from eating the matza and maror before midnight, he should eat them after midnight, in order to fulfill the mitzva according to R. Akiva’s opinion. However, he should not recite the berakhot of “al akhilat matza” and “al akhilat maror” over them so as to avoid reciting a berakha in vain (“le-vatala”) according to the opinion of R. Elazar b. Azarya (MB 477:6; Kaf Ha-ḥayim 10 ad loc.).
Regarding the afikoman as well, le-khatḥila one must take care to eat it before midnight, in order to fulfill the mitzva according to all poskim (SA 477:1). Similarly, Hallel should also be completed before midnight le-khatḥila, because it is connected to the telling of the Exodus story, which must be told at a time appropriate for eating matza (Rema ad loc.).
There were Torah scholars who, le-khatḥila, ate the afikoman after midnight, reasoning that the afikoman is a rabbinic enactment and we may thus rely upon the lenient opinion that it may be eaten after midnight. However, with regard to the initial kezayit of matza, which is a Torah commandment, and the maror, over which we recite a berakha, one may not adopt the lenient position and eat them before midnight.
However, one certainly must ensure that he eats a kezayit of matza before midnight, since eating a kezayit of matza is a Torah commandment, and hence one must be stringent. One must even be stringent vis-à-vis the mitzva of maror, since he cannot recite the berakha on it after midnight, as explained in MB 477:6 and BHL ad loc. Responsa Mishkenot Yaakov §139 and other Aḥaronim attempt to prove that the halakha follows Rambam. Nonetheless, the law still remains unclear, so one should not recite the berakhot on matza or maror after midnight and must likewise take care to fulfill the Torah obligation of matza before midnight. MB further states that if one begins late and does not have time to complete the recitation of the Hagada before midnight, he should eat the matza and maror, with berakhot, right after kiddush, and then recite the Hagada. Kaf Ha-ḥayim 477:10 echoes this idea, but rules that one may not recite the Birkat Ha-ge’ula (just before the second cup) after midnight, since we are lenient in a case of uncertainty regarding berakhot. See Ḥazon Ovadia vol. 2 p. 166, which agrees with MB and rules that one may recite Birkat Ha-ge’ula after midnight. Regarding the concluding berakha of Hallel, MB 477:7 and SHT 6 ad loc. cite Ḥok Yaakov that one may recite it after midnight.