The final redemption follows this pattern, but in the reverse direction. Yehoshua, of the tribe Ephraim, represents Moshiach ben Yosef. Moshe represents Moshiach ben David. (As Moshe was from the tribe of Levi, we learn from this that Moshiach ben David need not davka be a "Ben-Acher-Ben" descendent of David and need not even be of the tribe of Yehuda.) Moshiach ben Yosef will conquer the Land and will then transfer the scepter to Moshiach ben David. The transition may involve the death of Moshiach ben Yosef, but it need not be. The secret is that Yehuda unites the nation by coming from the left and cleaving to the right. Ben Yosef and ben David can be as Aharon and Moshe, as Moshe and Aharon, one.
The death of Moshe was caused by the sins of Israel, which brought much suffering that could have been avoided. Likewise, the death of Moshiach ben Yosef will not need to be if Israel will do Teshuva. The transition from Moshiach ben Yosef to Moshiach ben David will then be graceful, and very much suffering will be avoided.
ל