Reference: The most probable reference for this scripture is:
Matthew 19:30
30 But many that are first shall be last; and the last shall be first.
Of course this is not a text that would have been scripture (in the sense of written down) for Moroni. That it is referenced as fulfillment of scripture has to come from the association of Joseph’s understanding of that text to the situation explained by Moroni. Clearly the events of the last days come as fulfillment of scripture. It would appear that this particular fulfillment is pulled from Joseph’s understanding rather than what was directly on the plates.
The application of the scripture of the reversal of first and last is difficult to apply to this particular context. The typical use of the phrase was to indicate the reversal of the house of Israel with the Gentiles. That is clearly not the case here. The context here is the separation from Israel and the reuniting of Israel in the two Jerusalems. Perhaps the New Jerusalem/Old Jerusalem creates the first/last reversal in some way that its not particularly clear.