Announcing retreat does not move your ships yet: you still roll dice and assign hits before the Retreat step.
If the opponent has no ships left before then, combat ends and the announced retreat does not happen.
LRR v2.0 (base game / Prophecy of Kings); specific card abilities may override the general rule.