When they realized they were about to lose, they surrendered.

Literal

Lose-seeming [nominalizer-の] [subject-が] understood [when-とき], they [topic-は] surrendered.

負けそうになる combines ~そう (looks like) with ~になる (become) — 'it comes to look like losing.' The のが marks this realization as the subject of わかる.