How should I insulate behind the last floor joist that runs parallel to the foundation wall?
Since you have a gap, spray foam is probably your best option. During framing, there are corners and other locations that get insulated when the walls are being raised because they are inaccessible later on. At that stage, some rigid foam insulation is useful since it won't mold like fiberglass will and the structure isn't weather tight yet. If you didn't have a gap, drilling a small hole and using blown insulation would have been the best option.

For reference, a "rim joist" is the last joist on the row and wraps around the outside of the floor structure.