diff --git a/libraries.module b/libraries.module
index 751ecea..09b4fae 100644
--- a/libraries.module
+++ b/libraries.module
@@ -365,10 +365,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 in dependency order to make sure base theme template files are
+    // included before children 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;
@@ -434,6 +436,40 @@ function &libraries_info($name = NULL) {
 }
 
 /**
+ * Returns all active themes sorted by their depedencies.
+ *
+ * @return array
+ *   An associative array of theme objects keyed by theme name.
+ */
+function _libraries_get_enabled_themes() {
+  $themes = array_filter(list_themes(), function ($theme_info) { return !empty($theme_info->status); });
+
+  // Sort themes by dependencies and then alphabetically. Use key sorting to
+  // preserve keys.
+  uksort($themes, function ($a_key, $b_key) use ($themes) {
+    $a = $themes[$a_key];
+    $b = $themes[$b_key];
+    $a_parent = !empty($a->base_theme) ? $a->base_theme : NULL;
+    $b_parent = !empty($b->base_theme) ? $b->base_theme : NULL;
+
+    if ($b_parent === $a->name) {
+      $result = -1;
+    }
+    elseif ($a_parent === $b->name) {
+      $result = 1;
+    }
+    else {
+      $result = strcmp($a->name, $b->name);
+    }
+
+    return $result;
+  });
+
+
+  return $themes;
+}
+
+/**
  * Applies default properties to a library definition.
  *
  * @param array $library
