If your only concerned about critters, depending on the actual size of the gap (mouse sized to raccoon sized) a "combination of chicken wire-like mesh and rolled fiberglass insulation pressed gently into gap should work. I wouldn't spray foam alone, critters of all kinds could still chew and peck through it.
This is a sure sign that the roof line/rooms are not original to the house and proper integration of it was not incorporated into existing structure properly. I would look closely for other issues. The attic ventilation is important, so the gap is acceptable for that, however there should already be adequate ventilation. The concern remains to be wildlife intrusion, structural integrity and severe weather. Water could be forced up into the gap more readily then soffit ventilation due to the sloping roof line beneath it. And shingles need to rest upon a structural surface underneath them. Here in Florida during hurricane season winds would rip those shingles off and several more with it increasing the amount of rain that could soak the space and anything below.