diff --git a/AddHandler.hs b/AddHandler.hs
--- a/AddHandler.hs
+++ b/AddHandler.hs
@@ -120,9 +120,20 @@
         | otherwise = x : go xs
 
 fixCabal :: String -> String -> String
-fixCabal name =
-    unlines . reverse . go . reverse . lines
+fixCabal name orig =
+    unlines $ (reverse $ go $ reverse libraryLines) ++ restLines
   where
+    origLines = lines orig
+
+    (libraryLines, restLines) = break isExeTestBench origLines
+
+    isExeTestBench x = any
+        (\prefix -> prefix `isPrefixOf` x)
+        [ "executable"
+        , "test-suite"
+        , "benchmark"
+        ]
+
     l = "                  Handler." ++ name
 
     go [] = [l]
diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 1.4.18.3
+
+* Adding a new handler adds it under wrong stanza [#1273](https://github.com/yesodweb/yesod/issues/1273)
+
 ## 1.4.18.2
 
 * Work around change in behavior in newer optparse-applicative ([mailing list discussion](https://groups.google.com/d/msg/yesodweb/BrTkMKFREgU/AKVc9AK2AQAJ))
diff --git a/yesod-bin.cabal b/yesod-bin.cabal
--- a/yesod-bin.cabal
+++ b/yesod-bin.cabal
@@ -1,5 +1,5 @@
 name:            yesod-bin
-version:         1.4.18.2
+version:         1.4.18.3
 license:         MIT
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
