This tells me that it's an electrical problem.
The next time this happens (and you've made it to the side of the road safely) open the hood and
push a few electrical connections tight and see if your car starts. If not, push in a few more et cetera.
This happened to me 15 or more years ago several times (same symptoms as you experienced) and I did this, car fired right up, hasn't happened since.
Thing was - I was in a sketch part of the world, pushed in (tight) every electric connection under the hood in under 90 seconds, she fired up and I was outta there. In hindsight I wished I'd have been more patient with trying to find out exactly what was causing the problem. But the shot in the dark worked.