diff --git a/scripts/ai/tpl/generic.lua b/scripts/ai/tpl/generic.lua
index 7e9e67c..d71bdea 100644
--- a/scripts/ai/tpl/generic.lua
+++ b/scripts/ai/tpl/generic.lua
@@ -33,11 +33,6 @@ function control()
       attack_think()
     end
 
-  -- Enemy sighted.
-  elseif enemy ~= nil and aggressive then
-    taunt(enemy, true)
-    ai.pushtask(0, "attack", enemy)
-
   -- Pilot is running away.
   elseif task == "runaway" then
     dist = ai.dist(ai.pos(ai.targetid()))
@@ -51,6 +46,11 @@ function control()
       ai.hyperspace()
     end
 
+  -- Enemy sighted, handled after running away.
+  elseif enemy ~= nil and aggressive then
+    taunt(enemy, true)
+    ai.pushtask(0, "attack", enemy)
+
   -- Enter hyperspace if possible.
   elseif task == "hyperspace" then
     ai.hyperspace() -- Try to hyperspace.