diff --git a/twisted/conch/ssh/userauth.py b/twisted/conch/ssh/userauth.py
--- a/twisted/conch/ssh/userauth.py
+++ b/twisted/conch/ssh/userauth.py
@@ -836,7 +836,8 @@ MSG_USERAUTH_INFO_RESPONSE    = 61
 MSG_USERAUTH_PK_OK            = 60
 
 messages = {}
-for k, v in locals().items():
+# Sorting ensures MSG_USERAUTH_PK_OK comes last.
+for k, v in sorted(globals().items()):
     if k[:4]=='MSG_':
         messages[v] = k # doesn't handle doubles
 
diff --git a/twisted/conch/test/test_userauth.py b/twisted/conch/test/test_userauth.py
--- a/twisted/conch/test/test_userauth.py
+++ b/twisted/conch/test/test_userauth.py
@@ -1060,3 +1060,16 @@ class LoopbackTestCase(unittest.TestCase
         def check(ignored):
             self.assertEqual(server.transport.service.name, 'TestService')
         return d.addCallback(check)
+
+
+
+class ModuleInitializationTestCase(unittest.TestCase):
+
+
+    def test_messages(self):
+        # Several message types have value 60, check that MSG_USERAUTH_PK_OK
+        # is always the one which is mapped.
+        self.assertEqual(userauth.SSHUserAuthServer.protocolMessages[60],
+                         'MSG_USERAUTH_PK_OK')
+        self.assertEqual(userauth.SSHUserAuthClient.protocolMessages[60],
+                         'MSG_USERAUTH_PK_OK')
