You could disband your unit, then you wouldn't be attacking the region and could leave furtively.
Alternatively, you could swear allegiance to the other realm (unless it's rogue).
There are not many choices to be had when you are in enemy territory with a military unit....