בראשית מח, כב לַע דַחַא םֶכְׁש
מסכת בבא בתרא דף קכג/א ת"ש והבכורה ליוסף וכי תימא יוסף גופיה ממאי דפי שנים כאחד הוה תא שמע ואני נתתי לך שכם אחד על אחיך א"ל רב פפא לאביי אימא דיקלא בעלמא א"ל עליך אמר קרא אפרים ומנשה כראובן ושמעון יהיו לי
Yosef received two portions similar to two of the portions of each of the other brothers (one for Efraim and one for Menashe). It is understood that the first-born status was transferred from Reuven to Yosef as a result of the actions of Reuven in moving the “bed” of Yaacov.
How is it possible to take away the rights of first-born, since that is against Halacha? It is possible to understand this from the Ramban. The verse says not to remove the rights of the first born from a son of a hated wife to the son of a beloved wife. Ramban says this is not possible על פני, while the son is alive. But after death, the first-born rights can be removed from the inheritors. In our verse, it is also referring to the rights that occur after the death of Reuven (the future division of Eretz Israel); thus, it was permissible for Yaacov to remove the first-born status from Reuven (taking effect after death).