From Chabad's website:
http://www.chabad.org/library/moshiach/article_cdo/aid/101747/jewish/Appendix-II.htmJewish tradition speaks of two redeemers, each one called Mashiach. Both are involved in ushering in the Messianic era. They are Mashiach ben David and Mashiach ben Yossef.1
The term Mashiach unqualified always refers to Mashiach ben David (Mashiach the descendant of David) of the tribe of Judah. He is the actual (final) redeemer who shall rule in the Messianic age. All that was said in our text relates to him.
Mashiach ben Yossef (Mashiach the descendant of Joseph) of the tribe of Ephraim (son of Joseph), is also referred to as Mashiach ben Ephrayim, Mashiach the descendant of Ephraim.2 He will come first, before the final redeemer, and later will serve as his viceroy.3
The essential task of Mashiach ben Yossef is to act as precursor to Mashiach ben David: he will prepare the world for the coming of the final redeemer. Different sources attribute to him different functions, some even charging him with tasks traditionally associated with Mashiach ben David (such as the ingathering of the exiles, the rebuilding of the Bet Hamikdash, and so forth).4
The principal and final function ascribed to Mashiach ben Yossef is of political and military nature. He shall wage war against the forces of evil that oppress Israel. More specifically, he will do battle against Edom, the descendants of Esau.5 Edom is the comprehensive designation of the enemies of Israel,6 and it will be crushed through the progeny of Joseph. Thus it was prophesied of old, "The House of Jacob will be a fire and the House of Joseph a flame, and the House of Esau for stubble.." (Obadiah 1:18): "the progeny of Esau shall be delivered only into the hands of the progeny of Joseph."7
This ultimate confrontation between Joseph and Esau is alluded already in the very birth of Joseph when his mother Rachel exclaimed, "G‑d has taken away my disgrace" (Genesis 30:23): with prophetic vision she foresaw that an "anointed savior" will descend from Joseph and that he will remove the disgrace of Israel.8 In this context she called his name "Yossef, saying 'yossef Hashem - may G‑d add to me ben acher (lit., another son), i.e., ben acharono shel olam - one who will be at the end of the world's time,'9 from which it follows that 'meshu'ach milchamah - one anointed for battle' will descend from Joseph."10
The immediate results of this war11 will be disastrous: Mashiach ben Yossef will be killed. This is described in the prophecy of Zechariah, who says of this tragedy that "they shall mourn him as one mourns for an only child." (Zechariah 12:10).12 His death will be followed by a period of great calamities. These new tribulations shall be the final test for Israel, and shortly thereafter Mashiach ben David shall come, avenge his death, resurrect him, and inaugurate the Messianic era of everlasting peace and bliss.13
This, in brief, is the general perception of the "second Mashiach," the descendant of Joseph through the tribe of Ephraim.
Quite significantly, R. Saadiah Gaon (one of the few to elaborate on the role of Mashiach ben Yossef) notes that this sequence is not definite but contingent! Mashiach ben Yossef will not have to appear before Mashiach ben David, nor will the activities attributed to him or his death have to occur. All depends on the spiritual condition of the Jewish people at the time the redemption is to take place:
The essential function of Mashiach ben Yossef is to prepare Israel for the final redemption, to put them into the proper condition in order to clear the way for Mashiach ben David to come. Of that ultimate redemption it is said, that if Israel repent (return to G‑d) they shall be redeemed immediately (even before the predetermined date for Mashiach's coming). If they will not repent and thus become dependent on the final date, "the Holy One, blessed be He, will set up a ruler over them, whose decrees shall be as cruel as Haman's, thus causing Israel to repent, and thereby bringing them back to the right path."14 In other words, if Israel shall return to G‑d on their own and make themselves worthy of the redemption, there is no need for the trials and tribulations associated with the above account of events related to Mashiach ben Yossef. Mashiach ben David will come directly and redeem us.15
Moreover, even if there be a need for the earlier appearance of Mashiach ben Yossef, the consequences need not be as severe as described. Our present prayers and meritorious actions can mitigate these. R. Isaac Luria (Ari-zal) notes that the descendant of Joseph, by being the precursor of the ultimate Mashiach, is in effect kissey David, the "seat" or "throne" of David, i.e., of Mashiach. Thus when praying in the daily Amidah, "speedily establish the throne of Your servant David," one should consider that this refers to Mashiach ben Yossef and beseech G‑d that he should not die in the Messianic struggle.16 As all prayers, this one, too, will have its effect.
It follows, then, that all the above is not an essential or unavoidable part of the Messianic redemption that we await. Indeed, it - (and the same may be said of the climactic war of Gog and Magog) - may occur (or may have occured already!) in modified fashion.17 This may explain why Rambam does not mention anything about Mashiach ben Yossef. R. Saadiah Gaon18 and R. Hai Gaon,19 as well as a good number of commentators, do refer to him briefly or at length. In view of the divergent Midrashim and interpretations on this subject it is practically impossible to present a more definitive synopsis that would go far beyond the above. Thus it is wisest to cite and follow R. Chasdai Crescas who states that "no certain knowledge can be derived from the interpretations of the prophecies about Mashiach ben Yossef, nor from the statements about him by some of the Geonim;" there is no point, therefore, in elaborating on the subject.20
FOOTNOTES
1.
See Sukah 52b; Zohar I:25b; ibid. II:120a, III:153b, 246b and 252a. (See Sha'arei Zohar on Sukah 52a for further relevant sources in the Zohar-writings.)
2.
Sukah 52a-b; Zohar I:25b; ibid. III:246b and 252b etc.; and Midrash Agadat Mashiach; use the term Mashiach ben Yossef. Targum Yehonathan on Exodus 40:11; Zohar II:120a; ibid. 153b, 194b, and 243b etc.; Midrash Tehilim 60:3; and other Midrashim refer to Mashiach ben Ephrayim. Pesikta Rabaty, ch. 36-37 (ed. Friedmann, ch. 35-36) refers to Ephrayim Meshiach Tzidki (Ephraim, My righteous Mashiach); the term Ephraim, though, may relate here to collective Israel, thus referring to Mashiach ben David.
Pirkei Heichalot Rabaty, ch. 39 (Batei Midrashot, ed. Wertheimer, vol. I) and Sefer Zerubavel (ibid., vol. II), offer his personal name as Nechemiah ben Chushiel (likewise in Midrash Tehilim 60:3), adding "who is of Ephraim the son of Joseph." (Interestingly enough, Pirkei deR. Eliezer, ch. 19, calls him Menachem ben Ammi'el, the very name the other sources - and Zohar III:173b - attribute to Mashiach ben David.
Targum Yehonathan on Exodus 40:11 traces his descent to Joshua (cf. below, note 7). Other sources state that he is a descendant of Yeravam ben Nevat, with practical implications in the Providential scheme for this genealogy; see Zohar Chadash, Balak:56b; commentary of R. Abraham Galante on Zohar II:120a (cited in Or Hachamah there); and Emek Hamelech, Sha'ar Olam Hatohu:ch. 46. Cf Devash Lefi, s.v. mem:par. 18. (Note also the sources cited in Sha'arei Zohar on Sukah 52a with regards to other views about his lineage.)
3.
The harmony and cooperation between Mashiach ben David and Mashiach ben Yossef signifies the total unity of Israel, removing the historical rivalries between the tribes of Judah and Joseph; see Isaiah 11:13 and Rashi there. (Cf. Bereishit Rabba 70:15; and Torah Shelemah on Genesis 29:16, note 49.)
4.
See Pirkei Heichalot Rabaty, ch. 39; Sefer Zerubavel; Midrash Agadat Mashiach (most of which is quoted in Lekach Tov, Balak, on Numbers 24:17ff.); and cf. Rashi on Sukah 52b, s.v. charashim. See also Ramban, Commentary on Song 8:13.
5.
Note that the final battle of Mashiach ben Yossef is said to be against Armilus, ruler of Edom. See the Messianic Midrashim Zerubavel; Agadat Mashiach; Vayosha etc. (Specific references are offered in R. Margolius, Malachei Elyon, part II, s.v. Armilas; and see also the sources cited below, notes 18-19.) Note that the final battle of Mashiach ben Yossef is said to be against Armilus, ruler of Edom. See the Messianic Midrashim Zerubavel; Agadat Mashiach; Vayosha etc. (Specific references are offered in R. Margolius, Malachei Elyon, part II, s.v. Armilas; and see also the sources cited below, notes 18-19.)
6.
Edom is the perpetual enemy of Israel (see Sifre, Beha'alotecha, par. 69, cited by Rashi on Genesis 33:4; and see also Megilah 6a) and its final foe: the present galut is referred to as the galut of Edom (see Bereishit Rabba 44:17; Vayikra Rabba 13:5; and parallel passages) and Edom will be defeated ultimately by Mashiach (Obadiah; Yoma 10a; Midrash Tehilim 6:2; and cf. Tanchuma, Bo:4).
Interestingly enough, according to Pirkei deR. Eliezer ch. 28 (in non-censored versions), the Ishmaelites (Arabs) will be the final kingdom to be defeated by Mashiach. Other sources state "Edom and Ishmael" (see Torah Shelemah on Genesis 15:12, note 130). Note, however, Pirkei deR. Eliezer, ch. 44 (and cf. Midrash Tehilim 2:6 and 83:3) that Edom and Ishmael have become intermingled. See also Mayanei Hayeshu'ah, Mayan 11:8.
7.
Baba Batra 123b. Targum Yehonathan on Genesis 30:23. Tanchuma, ed. Buber, Vayetze:15; and Bereishit Rabba 73:7; and the parallel passages cited there. See Bereishit Rabba 99:2, that Edom shall fall by the meshu'ach milchamah (the one anointed for battle; see below, note 10 for this term) who will be descended from Joseph.
Mashiach ben Yossef's battle against Edom is analogous to, and the culmination of, Israel's first battle against Edom (Amalek) after the exodus from Egypt (Exodus 17:5ff.). In that first battle, the Jewish army was led by Joshua - who is also of the tribe of Ephraim, and (according to some) this Mashiach's ancestor (see above note 2); see Ramban on Exodus 17:9, and R. Bachaya on Exodus 18:1. Cf. also R. Bachaya on Exodus 1:5, drawing an analogy between the role of Joseph in Egypt and the role of the Mashiach descended from him in the ultimate redemption.
8.
The Messianic aspect is derived by analogy with Isaiah 4:1.
9.
The Messianic aspect is derived by analogy with Genesis 4:25 which in Agadat Mashiach (cited in Lekach Tov on Numbers 24:17) is put into Messianic context.
10.
Midrash Yelamdenu, cited in Kuntres Acharon of Yalkut Shimoni. (This Kuntres Acharon appears only in very few editions of Yalkut Shimoni, but was republished in Jellinek's Bet Hamidrash, vol. VI. Our passage appears there on p. 81, par. 20; and is also cited in Torah Shelemah on Genesis 30:23-24, par. 84 and 89.)
In context of his military function, Mashiach ben Yossef is referred to as meshu'ach milchamah (cf. Sotah 42a, and Rashi on Deuteronomy 20:2, for this term); see Bereishit Rabba 75:6 and 99:2; Shir Rabba 2:13 (a parallel passage of Sukah 52b); and Agadat Bereishit, ch. (63) 64.
11.
Targum Yehonathan on Exodus 40:11, and on Zechariah 12:10 (manuscript-version in ed. A. Sperber); Agadat Mashiach; Pirkei Heichalot Rabaty (in version cited by Ramban, Sefer Hage'ulah, sha'ar IV; ed. Chavel, p. 291); and Rashi on Sukah 52a; identify the battle of Mashiach ben Yossef with the war of Gog and Magog.
12.
Sukah 52a, and parallel passages.
13.
Pirkei Heichalot Rabaty, ch. 39 (cited in Sefer Hage'ulah, sha'ar IV); Sefer Zerubavel; Agadat Mashiach (cited in Lekach Tov, ibid.). See R. Saadiah Gaon, Emunot Vede'ot VIII:ch. 5, adding Scriptural "prooftexts" or allusions for all details; and the lengthy responsum of R. Hai Gaon on the redemption, published in Otzar Hageonim on Sukah 52a, and in Midreshei Ge'ulah, ed. Y. Ibn Shemuel, p. 135ff. Cf. Rashi and Ibn Ezra on Zechariah 12:10; Ibn Ezra and Redak on Zechariah 13:7.
14.
Sanhedrin 97b
15.
Emunot Vede'ot VIII:6; see there at length. Cf. Or Hachayim on Numbers 24:17.
16.
Peri Eitz Chayim, Sha'ar Ha'amidah:ch. 19; and Siddur Ha-Ari; on this blessing. The Ari's teaching is cited in Or Hachayim on Leviticus 14:9, see there (and also on Numbers 24:17, where he relates this prayer to the next blessing of the Amidah); and see also Even Shelemah, ch. 11, note 6. Cf. Zohar II:120a (and Or Hachamah there), and ibid. III:153b. See next note.
17.
The battle of Gog and Magog (see above, Appendix I, note 2) is another of the complex issues of the Messianic redemption. In fact, an authoritative tradition from the disciples of the Baal Shem Tov states that the extraordinary length of the present severe galut has already made up for the troubles of that battle and the trauma of the death of Mashiach ben Yossef, so that these will no longer occur; see R. Shemuel of Sochachev, Shem MiShemuel, Vayigash, s.v. Vayigash 5677 (s.v. venireh od, p. 298bf.).
18.
Emunot Vede'ot VIII:ch. 5-6. See also the commentary on Shir Hashirim attributed to R. Saadiah Gaon, published in Chamesh Megilot im Perushim Atikim (Miginzei Teyman), ed. Y. Kapach, on Song 7:12-14 (p. 115; and also in Midreshei Ge'ulah, p. 131f.; as noted already by the editors, this passage is most probably based on Sefer Zerubavel).
19.
See his extensive responsum, cited above note 13.
20.
Or Hashem, Ma'amar III, klal 8: end of ch. 1.