Think back to your training — did anything like this happen? How did you handle it?
Ask yourself if you need to shift your goal — maybe you were hoping for a “PR” (personal record) or a specific time, but now you’re just going to focus on finishing.
Seek out support (within race rules) — most marathons have aid stations and medical staff so if you need to get some help with a blister, chaffing, sprained ankle etc. do it. That’s what they’re here for.
Ask yourself if you can you make the situation better with the things you can control, like pace, form, and, at least to some extent, attitude — or is it going to take a miracle? If it’s the latter, what is the likelihood of a miracle happening?
Live to marathon (or just live) another day — a marathon will hurt no matter what, but if you fear you are putting your health in jeopardy, or that you may be doing permanent damage, it’s time to call it a day and head for the nearest aid station, medical tent, or on-course personnel. You can always decide to try again in the future.