She realized it was in her best interest to tell the truth.
Literal
She [topic-は] truth [object-を] said [alternative-方が] self [purpose-のためだと] realized.
本当のことを言ったほうが身のためだと悟った — 方がいい ('better to') is implied. 身のため ('for one's own sake') uses 身 figuratively. 悟る (さとる, 'to realize, become enlightened') is a literary verb.