diff --git a/cas.module b/cas.module
index 3b84d97..ff34cd4 100644
--- a/cas.module
+++ b/cas.module
@@ -634,11 +634,26 @@ function cas_login_page($cas_first_login = FALSE) {
 }
 
 /**
- * Logs a user out of drupal and then out of cas
+ * Mimic user_logout(), logging a user out of Drupal and then out of CAS.
  */
 function cas_logout() {
   global $user;
 
+  // Mimic user_logout().
+  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
+  module_invoke_all('user_logout', $user);
+
+  cas_logout_do_logout();
+}
+
+/**
+ * Do actual Drupal and CAS logout.
+ * This is safe to call from hook_user_logout() to ensure all Drupal logouts also logout CAS.
+ */
+function cas_logout_do_logout() {
+  // Drupal logout.
+  session_destroy();
+
   // Build the logout URL.
   cas_phpcas_init();
   $logout_url = phpCAS::getServerLogoutURL();
@@ -655,7 +670,7 @@ function cas_logout() {
     $destination = variable_get('cas_logout_destination', '');
   }
 
-  //Make it an absolute url.  This will also convert <front> to the front page.
+  // Make it an absolute url. This will also convert <front> to the front page.
   if ($destination) {
     $destination_url = url($destination, array('absolute' => TRUE));
     $options['query'] = array(
@@ -665,11 +680,6 @@ function cas_logout() {
     );
   }
 
-  // Mimic user_logout().
-  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
-  module_invoke_all('user_logout', $user);
-  session_destroy();
-
   // Force redirection in drupal_goto().
   unset($_GET['destination']);
   drupal_goto($logout_url, $options);
