What should I do when my faction is dying?

You have 3 options at this point:

  1. Gut it out, depending on how much territory your faction has remaining just do your best at defending your remaining land (prioritizing towns over castles), and retake any recently lost town (the NPC lords usually split and go off in their own directions after taking one). Eventually the other factions will declare peace or go to war with each other.

  2. Start your own faction. Go and take some territory and demand that the king give it to you. If he refuses, then strike out on your own. Your new territory won't be at war with anyone... yet.

  3. Similar to 2, find the claimant to your faction and declare for him.

The benefits of 2 & 3 are, if you already have good standing with the lords in your faction, it should be no problem to convince them to join your cause.