diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index a7da8d0..8803c2d 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1532,11 +1532,18 @@ function theme_enable($theme_list) {
  *   An array of theme names.
  */
 function theme_disable($theme_list) {
-  // Don't disable the default theme.
-  if ($pos = array_search(config('system.theme')->get('default'), $theme_list) !== FALSE) {
-    unset($theme_list[$pos]);
-    if (empty($theme_list)) {
-      return;
+  // Don't disable the default or admin themes.
+  $default_theme = config('system.theme')->get('default');
+  $admin_theme = config('system.theme')->get('admin');
+  $required_themes = array($default_theme, $admin_theme);
+
+  foreach ($required_themes as $theme) {
+    $pos = array_search($theme, $theme_list);
+    if ($pos !== FALSE) {
+      unset($theme_list[$pos]);
+      if (empty($theme_list)) {
+        return;
+      }
     }
   }
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
index 32f9321..963c6a2 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
@@ -257,4 +257,34 @@ public function testFindThemeTemplates() {
     $templates = drupal_find_theme_templates($cache, '.html.twig', drupal_get_path('theme', 'test_theme'));
     $this->assertEqual($templates['node__1']['template'], 'node--1', 'Template node--1.html.twig was found in test_theme.');
   }
+
+  /** 
+   * Test that themes can be disabled programmatically.
+   */
+  function testDisableTheme() {
+    // Enable Bartik and Seven.
+    theme_enable(array('bartik', 'seven'));
+
+    // Set Bartik as the default theme and Seven as the admin theme.
+    config('system.theme')
+      ->set('default', 'bartik')
+      ->set('admin', 'seven')
+      ->save();
+
+    $theme_list = array_keys(list_themes());
+    // Attempt to disable all themes. theme_disable() ensures that the default
+    // theme and the admin theme will not be disabled.
+    theme_disable($theme_list);
+
+    // Ensure all themes are disabled
+    $themes = list_themes();
+    foreach ($themes as $theme_name => $theme) {
+      if ($theme_name == 'bartik' || $theme_name == 'seven') {
+        $this->assertTrue($theme->status == 1, 'Default theme and admin theme not disabled.');
+      }
+      else {
+        $this->assertTrue($theme->status == 0, 'Other themes disabled.');
+      }
+    }
+  }
 }
