One or Two: Mashiach ben Yosef and Mashiach ben Yehuda
(ז) וְ֠הִנֵּ֠ה אֲנַ֜חְנוּ מְאַלְּמִ֤ים אֲלֻמִּים֙ בְּת֣וֹךְ הַשָּׂדֶ֔ה וְהִנֵּ֛ה קָ֥מָה אֲלֻמָּתִ֖י וְגַם־נִצָּ֑בָה וְהִנֵּ֤ה תְסֻבֶּ֙ינָה֙ אֲלֻמֹּ֣תֵיכֶ֔ם וַתִּֽשְׁתַּחֲוֶ֖יןָ לַאֲלֻמָּתִֽי׃ (ח) וַיֹּ֤אמְרוּ לוֹ֙ אֶחָ֔יו הֲמָלֹ֤ךְ תִּמְלֹךְ֙ עָלֵ֔ינוּ אִם־מָשׁ֥וֹל תִּמְשֹׁ֖ל בָּ֑נוּ וַיּוֹסִ֤פוּ עוֹד֙ שְׂנֹ֣א אֹת֔וֹ עַל־חֲלֹמֹתָ֖יו וְעַל־דְּבָרָֽיו׃
(7) There we were binding sheaves in the field, when suddenly my sheaf stood up and remained upright; then your sheaves gathered around and bowed low to my sheaf.” (8) His brothers answered, “Do you mean to reign over us? Do you mean to rule over us?” And they hated him even more for his talk about his dreams.
(א) וַֽיְהִי֙ בָּעֵ֣ת הַהִ֔וא וַיֵּ֥רֶד יְהוּדָ֖ה מֵאֵ֣ת אֶחָ֑יו וַיֵּ֛ט עַד־אִ֥ישׁ עֲדֻלָּמִ֖י וּשְׁמ֥וֹ חִירָֽה׃
(1) About that time Judah left his brothers and camped near a certain Adullamite whose name was Hirah.
(כו) וַיַּכֵּ֣ר יְהוּדָ֗ה וַיֹּ֙אמֶר֙ צָֽדְקָ֣ה מִמֶּ֔נִּי כִּֽי־עַל־כֵּ֥ן לֹא־נְתַתִּ֖יהָ לְשֵׁלָ֣ה בְנִ֑י וְלֹֽא־יָסַ֥ף ע֖וֹד לְדַעְתָּֽהּ׃
(26) Judah recognized them, and said, “She is more in the right than I, inasmuch as I did not give her to my son Shelah.” And he was not intimate with her again.
(א) וְיוֹסֵ֖ף הוּרַ֣ד מִצְרָ֑יְמָה וַיִּקְנֵ֡הוּ פּוֹטִיפַר֩ סְרִ֨יס פַּרְעֹ֜ה שַׂ֤ר הַטַּבָּחִים֙ אִ֣ישׁ מִצְרִ֔י מִיַּד֙ הַיִּשְׁמְעֵאלִ֔ים אֲשֶׁ֥ר הוֹרִדֻ֖הוּ שָֽׁמָּה׃
(1) When Joseph was taken down to Egypt, Potiphar, a courtier of Pharaoh and his prefect —a [type of] Egyptian official —bought him from the Ishmaelites who had brought him there.
(מא) וַיֹּ֥אמֶר פַּרְעֹ֖ה אֶל־יוֹסֵ֑ף רְאֵה֙ נָתַ֣תִּי אֹֽתְךָ֔ עַ֖ל כׇּל־אֶ֥רֶץ מִצְרָֽיִם׃
(41) Pharaoh further said to Joseph, “See, I put you in charge of all the land of Egypt.”
(יח) וַיִּגַּ֨שׁ אֵלָ֜יו יְהוּדָ֗ה וַיֹּ֘אמֶר֮ בִּ֣י אֲדֹנִי֒ יְדַבֶּר־נָ֨א עַבְדְּךָ֤ דָבָר֙ בְּאׇזְנֵ֣י אֲדֹנִ֔י וְאַל־יִ֥חַר אַפְּךָ֖ בְּעַבְדֶּ֑ךָ כִּ֥י כָמ֖וֹךָ כְּפַרְעֹֽה׃
(18) Then Judah went up to him and said, “Please, my lord, let your servant appeal to my lord, and do not be impatient with your servant, you who are the equal of Pharaoh.
(ד) וַיֹּ֨אמֶר יוֹסֵ֧ף אֶל־אֶחָ֛יו גְּשׁוּ־נָ֥א אֵלַ֖י וַיִּגָּ֑שׁוּ וַיֹּ֗אמֶר אֲנִי֙ יוֹסֵ֣ף אֲחִיכֶ֔ם אֲשֶׁר־מְכַרְתֶּ֥ם אֹתִ֖י מִצְרָֽיְמָה׃ (ה) וְעַתָּ֣ה ׀ אַל־תֵּעָ֣צְב֗וּ וְאַל־יִ֙חַר֙ בְּעֵ֣ינֵיכֶ֔ם כִּֽי־מְכַרְתֶּ֥ם אֹתִ֖י הֵ֑נָּה כִּ֣י לְמִֽחְיָ֔ה שְׁלָחַ֥נִי אֱלֹהִ֖ים לִפְנֵיכֶֽם׃
(4) Then Joseph said to his brothers, “Come forward to me.” And when they came forward, he said, “I am your brother Joseph, he whom you sold into Egypt. (5) Now, do not be distressed or reproach yourselves because you sold me hither; it was to save life that God sent me ahead of you.
(י) וְשָׁפַכְתִּי֩ עַל־בֵּ֨ית דָּוִ֜יד וְעַ֣ל ׀ יוֹשֵׁ֣ב יְרוּשָׁלַ֗͏ִם ר֤וּחַ חֵן֙ וְתַ֣חֲנוּנִ֔ים וְהִבִּ֥יטוּ אֵלַ֖י אֵ֣ת אֲשֶׁר־דָּקָ֑רוּ וְסָפְד֣וּ עָלָ֗יו כְּמִסְפֵּד֙ עַל־הַיָּחִ֔יד וְהָמֵ֥ר עָלָ֖יו כְּהָמֵ֥ר עַֽל־הַבְּכֽוֹר׃
(10) But I will fill the House of David and the inhabitants of Jerusalem with a spirit of pity and compassion; and they shall lament to Me about those who are slain, wailing over them as over a favorite son and showing bitter grief as over a first-born.

הָא הֶסְפֵּידָא מַאי עֲבִידְתֵּיהּ? פְּלִיגִי בַּהּ רַבִּי דּוֹסָא וְרַבָּנַן. חַד אָמַר: עַל מָשִׁיחַ בֶּן יוֹסֵף שֶׁנֶּהֱרַג, וְחַד אָמַר: עַל יֵצֶר הָרַע שֶׁנֶּהֱרַג. בִּשְׁלָמָא לְמַאן דְּאָמַר עַל מָשִׁיחַ בֶּן יוֹסֵף שֶׁנֶּהֱרַג, הַיְינוּ דִּכְתִיב: ״וְהִבִּיטוּ אֵלַי אֵת אֲשֶׁר דָּקָרוּ וְסָפְדוּ עָלָיו כְּמִסְפֵּד עַל הַיָּחִיד״. אֶלָּא לְמַאן דְּאָמַר עַל יֵצֶר הָרַע שֶׁנֶּהֱרַג — הַאי הֶסְפֵּידָא בָּעֵי לְמֶעְבַּד? שִׂמְחָה בָּעֵי לְמֶעְבַּד! אַמַּאי בָּכוּ? כִּדְדָרֵשׁ רַבִּי יְהוּדָה: לֶעָתִיד לָבֹא, מְבִיאוֹ הַקָּדוֹשׁ בָּרוּךְ הוּא לְיֵצֶר הָרָע, וְשׁוֹחֲטוֹ בִּפְנֵי הַצַּדִּיקִים וּבִפְנֵי הָרְשָׁעִים. צַדִּיקִים נִדְמֶה לָהֶם כְּהַר גָּבוֹהַּ, וּרְשָׁעִים נִדְמֶה לָהֶם כְּחוּט הַשַּׂעֲרָה. הַלָּלוּ בּוֹכִין וְהַלָּלוּ בּוֹכִין. צַדִּיקִים בּוֹכִין וְאוֹמְרִים: הֵיאַךְ יָכוֹלְנוּ לִכְבּוֹשׁ הַר גָּבוֹהַּ כָּזֶה! וּרְשָׁעִים בּוֹכִין וְאוֹמְרִים: הֵיאַךְ לֹא יָכוֹלְנוּ לִכְבּוֹשׁ אֶת חוּט הַשַּׂעֲרָה הַזֶּה! וְאַף הַקָּדוֹשׁ בָּרוּךְ הוּא תָּמֵהַּ עִמָּהֶם, שֶׁנֶּאֱמַר: ״כֹּה אָמַר ה׳ צְבָאוֹת כִּי יִפָּלֵא בְּעֵינֵי שְׁאֵרִית הָעָם הַזֶּה בַּיָּמִים הָהֵם גַּם בְּעֵינַי יִפָּלֵא״. תָּנוּ רַבָּנַן: מָשִׁיחַ בֶּן דָּוִד שֶׁעָתִיד לְהִגָּלוֹת בִּמְהֵרָה בְּיָמֵינוּ, אוֹמֵר לוֹ הַקָּדוֹשׁ בָּרוּךְ הוּא: שְׁאַל מִמֶּנִּי דָּבָר וְאֶתֵּן לָךְ, שֶׁנֶּאֱמַר: ״אֲסַפְּרָה אֶל חוֹק וְגוֹ׳ אֲנִי הַיּוֹם יְלִדְתִּיךָ. שְׁאַל מִמֶּנִּי וְאֶתְּנָה גוֹיִם נַחֲלָתֶךָ״. וְכֵיוָן שֶׁרָאָה מָשִׁיחַ בֶּן יוֹסֵף שֶׁנֶּהֱרַג, אוֹמֵר לְפָנָיו: רִבּוֹנוֹ שֶׁל עוֹלָם! אֵינִי מְבַקֵּשׁ מִמְּךָ אֶלָּא חַיִּים. אוֹמֵר לוֹ: חַיִּים, עַד שֶׁלֹּא אָמַרְתָּ כְּבָר הִתְנַבֵּא עָלֶיךָ דָּוִד אָבִיךָ, שֶׁנֶּאֱמַר: ״חַיִּים שָׁאַל מִמְּךָ נָתַתָּה לוֹ וְגוֹ׳״.

For what is the nature of this eulogy? The Gemara answers: Rabbi Dosa and the Rabbis disagree concerning this matter. One said that this eulogy is for Messiah ben Yosef who was killed in the war of Gog from the land of Magog prior to the ultimate redemption with the coming of Messiah ben David. And one said that this eulogy is for the evil inclination that was killed. The Gemara asks: Granted, according to the one who said that the lament is for Messiah ben Yosef who was killed, this would be the meaning of that which is written in that context: “And they shall look unto Me because they have thrust him through; and they shall mourn for him, as one mourns for his only son” (Zechariah 12:10). However, according to the one who said that the eulogy is for the evil inclination that was killed, does one need to conduct a eulogy for this? On the contrary, one should conduct a celebration. Why, then, did they cry? The Gemara answers: This can be understood as Rabbi Yehuda taught: In the future, at the end of days, God will bring the evil inclination and slaughter it in the presence of the righteous and in the presence of the wicked. For the righteous the evil inclination appears to them as a high mountain, and for the wicked it appears to them as a mere strand of hair. These weep and those weep. The righteous weep and say: How were we able to overcome so high a mountain? And the wicked weep and say: How were we unable to overcome this strand of hair? And even the Holy One, Blessed be He, will wonder with them, as it is stated with regard to the eulogy: “So says the Lord of hosts: If it be wondrous in the eyes of the remnant of this people in those days, it should also be wondrous in My eyes” (Zechariah 8:6). The Sages taught: To Messiah ben David, who is destined to be revealed swiftly in our time, the Holy One, Blessed be He, says: Ask of Me anything and I will give you whatever you wish, as it is stated: “I will tell of the decree; the Lord said unto me: You are My son, this day have I begotten you, ask of Me, and I will give the nations for your inheritance, and the ends of the earth for your possession” (Psalms 2:7–8). Once the Messiah ben David saw Messiah ben Yosef, who was killed, he says to the Holy One, Blessed be He: Master of the Universe, I ask of you only life; that I will not suffer the same fate. The Holy One, Blessed be He, says to him: Life? Even before you stated this request, your father, David, already prophesied about you with regard to this matter precisely, as it is stated: “He asked life of You, You gave it to him; even length of days for ever and ever” (Psalms 21:5).

(ג) ופירוש זה, כי אומה ישראלית הם דומים לאדם אחד, שיש בו שנים עשר אברים, והם מנויים וידועים, והם כנגד י"ב מזלות, וכנגד י"ב חדשי השנה. ויש באדם שני אברים, והם מלכים על כל האברים, והם הראש והלב. כי מלכות יהודה נגד הראש, וכדכתיב (ר' שופטים א, ב) "יהודה יעלה בראש". ויוסף תמיד הוא באמצע, כנגד הלב. [שכן] תמצא בנשיאים, נשיא אפרים באמצע, דומה ללב שהוא באמצע האדם. וידוע כי הנשמה הנבדלת היא במוח, והנשמה היא אלקית יותר מן הלב. וכן הוא מלכות יהודה, כאשר המלכות הוא כראוי, אז מקבלים כבוד ה', ואין כאן רק מלכות בית דוד. ולפיכך ראוי כי יהיה מלך אחד לכל י"ב שבטים, שהם י"ב אברי האדם. אבל כאשר אינם זוכים, אינם מקבלים לגמרי כבוד השם, ואין להם מעלה זאת כאשר ראוי, ואז נחלק המלכות. ורוב האברים נמשכים אל הלב, שהוא עיקר, ומעוט אל הראש, כאשר הוא בחסרון. לכך לא היה ליהודא רק שבט יהודא ובנימין, שהם האברים הקרובים ביותר לקבל כבוד השם, כאשר המקדש בחלקם. אבל שאר האברים, שהם השבטים, לא היו נמשכים אחריהם, כאשר לא היו ישראל במדריגה הזאת העליונה לקבל זה:

ומזה הטעם ראוי לישראל שיהיה להם משיח בן יוסף גם כן. שכיון שראוי שבט אפרים למלוכה, מצד שהשבט הזה דומה ללב, לכך יהיה להם בסוף המושל הזה, שהוא משיח בן יוסף. ומכל מקום גוברים עליו האומות, כי ממשלה ומעלה זאת יש לו הפסק ובטול. ולפיכך גוג ומגוג, שהוא מתנגד לישראל כמו שהתבאר, יהיה גובר על משיח בן יוסף, ויהיה נהרג ומסתלק מעלה זאת מן ישראל:

( וביאור עניין זה כמו שאמרנו למעלה, כי מעלת משיח בן יוסף יש לו הפסק, שיהיו גוברים עליו האומות, ויש הפסק למעלתו. אבל משיח שאל שלא יהיה הפסק למדריגתו, ולא יהיו גוברים עליו האומות. וזהו החיים אשר שאל, דהיינו כי אל כח מציאתו לא יהיה לו הפסק. לא כמו שהיה משיח בן יוסף, שהיה לכח שלו הפסק, אבל לכח מעלת משיח בן דוד לא יהיה לו הפסק. ואז יהיו גוים נחלתו ואחזתו אפסי ארץ, כי יתגבר משיח בן דוד על האומות, ויסלק כח האומות, ועמהם מסתלק היצר הרע:

(

The nation of Israel is comparable to a person with twelve (primary) limbs/organs... There are two limbs that are primary, and therefore have the potential to lead the other organs, the heart and the brain. The kingship of Yehuda corresponds to the head, and the kingship of Yosef to the heart...

Now, it is known that the seat of the Neshama is in the brain/mind, and the Neshama is more G-dly than the heart (which relates to ruach, a lower level of the soul).

So too, with regard to the kingship of Yehuda. When Jewish kingship is in its prime then the Jews attain a lofty level and there is only one king from the tribe of Yehuda. After all, the nation of Israel is one being, and it is appropriate that there be one king uniting everyone.

However, when they aren't worthy, the kingship is split between Yehuda and Yosef/Ephraim...

But the king from Yosef will not last, and the Mashiach ben Yosef will be killed during the war of Gog and Magog...

Mashiach ben David, however, will live on... This relates to the life that Mashiach ben David requests and is granted.

(טז) וְאַתָּ֣ה בֶן־אָדָ֗ם קַח־לְךָ֙ עֵ֣ץ אֶחָ֔ד וּכְתֹ֤ב עָלָיו֙ לִֽיהוּדָ֔ה וְלִבְנֵ֥י יִשְׂרָאֵ֖ל חֲבֵרָ֑ו וּלְקַח֙ עֵ֣ץ אֶחָ֔ד וּכְת֣וֹב עָלָ֗יו לְיוֹסֵף֙ עֵ֣ץ אֶפְרַ֔יִם וְכׇל־בֵּ֥ית יִשְׂרָאֵ֖ל חֲבֵרָֽו׃ (יז) וְקָרַ֨ב אֹתָ֜ם אֶחָ֧ד אֶל־אֶחָ֛ד לְךָ֖ לְעֵ֣ץ אֶחָ֑ד וְהָי֥וּ לַאֲחָדִ֖ים בְּיָדֶֽךָ׃

(16) And you, O mortal, take a stick and write on it, “Of Judah and the Israelites associated with him”; and take another stick and write on it, “Of Joseph—the stick of Ephraim—and all the House of Israel associated with him.” (17) Bring them close to each other, so that they become one stick, joined together in your hand.

Ramchal Maamar HaGeula והבן כי שני שבטים היו ליהודה, והעשרה לאפרים. ולעתיד יקבצו השנים על ידי משיח בן אפרים ויהיו נקשרים בו… והעשרה אחרים יבואו על ידי משיח בן דוד… ואז נאמר ״והיו לאחדים בידיך.״

Ramchal: Two tribes belonged to Yehuda and ten to Ephraim, but in the future, it will be Mashiach ben Ephraim who will redeem the two tribes, and Mashiach ben David who will redeem the ten.