In this instance I would say yes. Note there is no qualifier on 'moving disheartened troops that will end closer to enemy' so the type of enemy and things like visibility don't come into play.
In which case I don't have any issues with an initial movement that may be towards an enemy, provided the final position doesn't end closer to any enemy. This should be possible if say you had a single element very close to your rear corner, with all other enemy to your front - you could move past the single element provided you end your move further away from all enemy.