diff --git a/libraries.module b/libraries.module
index 0371521..7155b97 100644
--- a/libraries.module
+++ b/libraries.module
@@ -80,6 +80,56 @@ function libraries_get_path($name, $base_path = FALSE) {
 }
 
 /**
+ * Returns all enabled themes.
+ *
+ * Themes are sorted so that base themes always precede their child themes.
+ *
+ * @return array
+ *   An associative array of theme objects keyed by theme name.
+ */
+function libraries_get_enabled_themes() {
+  $themes = array();
+  foreach (list_themes() as $name => $theme) {
+    if ($theme->status) {
+      $themes[$name] = $theme;
+    }
+  }
+
+  uasort($themes, 'libraries_compare_themes');
+
+  return $themes;
+}
+
+/**
+ * Compares two themes.
+ *
+ * @param object $a
+ *   The first theme object.
+ * @param object $b
+ *   The second theme object.
+ *
+ * @return int
+ *   -1 if $a is the base theme of $b; 1 if $b is the base theme of $a; 0
+ *   otherwise.
+ */
+function libraries_compare_themes($a, $b) {
+  $a_base = !empty($a->base_theme) ? $a->base_theme : NULL;
+  $b_base = !empty($b->base_theme) ? $b->base_theme : NULL;
+
+  if ($b_base === $a->name) {
+    $result = -1;
+  }
+  elseif ($a_base === $b->name) {
+    $result = 1;
+  }
+  else {
+    $result = 0;
+  }
+
+  return $result;
+};
+
+/**
  * Returns an array of library directories.
  *
  * Returns an array of library directories from the all-sites directory
@@ -388,10 +438,12 @@ function &libraries_info($name = NULL) {
       }
     }
 
-    // Gather information from hook_libraries_info() in enabled themes.
+    // Gather information from hook_libraries_info() in enabled themes. Themes
+    // are sorted to ensure that a base theme's template.php is included before
+    // its children's ones.
     $themes = array();
-    foreach (list_themes() as $theme_name => $theme_info) {
-      if ($theme_info->status && file_exists(drupal_get_path('theme', $theme_name) . '/template.php')) {
+    foreach (libraries_get_enabled_themes() as $theme_name => $theme_info) {
+      if (file_exists(drupal_get_path('theme', $theme_name) . '/template.php')) {
         // Collect a list of viable themes for re-use when calling the alter
         // hook.
         $themes[] = $theme_name;
