Just to note, Rambam (Mishna Torah; Hil. Melachim 12:2) writes that one should not over-contemplate the events that are to come about with the redemption, for the prophecies are intentionally vague and no one will know for certain their meaning until they come to be realized. Even the Rabbis of the Talmud only said about the redemption and the Messiah what they could glean and derive from the verses of the Prophets, but did not have any sort of absolute knowledge or tradition as to what would happen.
That said, the Talmud (Succah 52a and 52b) does mention a figure known as "Mashiach ben Yosef", and does interpret a couple of verses in Zecharia in light of his existence. (In doing so, it is made clear that he will die in the apocalypse.) Who is this figure? It is not exactly clear.
R' Saadya Gaon (Emunot V'deot 8:6) seems to believe that his existence is only necessary if the Jews are not ready for the Messiah and need to do t'shuva to merit the redemption. [It is a common idea that the Messiah will come either if the Jews are meritorious, or if they are not, at a predetermined "deadline". R' Saadya is referring to if the Messiah must come at the "deadline", and the Jews need preparation to be redeemed.] In this case, the Mashiach ben Yosef will lead the Jews back to God's good graces allowing them to be worthy of redemption, and later he will die in battle (of Gog and Magog), allowing for the succession of the "real" Messiah, Mashiach ben David.
Abarbanel and Malbim, in their commentaries to the Prophets, treat the existence of Mashiach ben Yosef as a "kabbala" (tradition) known to Chazal from the prophets themselves. (See Abarbanel to Ezekiel 32 and Malbim to Ezekiel 37:19.) In their opinion, he will be (as indicated by his name) from the tribe of Yosef, or at least from one of the ten "lost tribes", who were exiled by Sancheriv. He will be instrumental in uniting the ten tribes with the rest of the Jews in exile, as well as uniting the Jews in exile themselves, and leading them in the final war leading to the Redemption, thereupon dying in battle.
According to some sources, Mashiach ben Yosef will be resurrected immediately after the war in the "Techiat Hameitim" (Resurrection of the Dead). Others maintain that he will remain dead so as not to detract from the monarchy of the Mashiach ben David.