diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 32f47fa..b5e1ca3 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -993,8 +993,11 @@ function drupal_page_is_cacheable($allow_caching = NULL) {
     $allow_caching_static = $allow_caching;
   }
 
+  // We cannot check _menu_site_is_offline in bootstrap.inc as menu.inc has
+  // not been loaded yet. Without checking the site is offline, maintenance
+  // pages may be cached and returned after maintenance mode is switched off.
   return $allow_caching_static && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD')
-    && !drupal_is_cli();
+    && !drupal_is_cli() && !Drupal::config('system.maintenance')->get('enabled');
 }
 
 /**
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/SiteMaintenanceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/SiteMaintenanceTest.php
index 1cb582a..d203148 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/SiteMaintenanceTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/SiteMaintenanceTest.php
@@ -119,4 +119,39 @@ function testSiteMaintenance() {
     $this->drupalPostForm($path, array(), t('Log in'));
     $this->assertText($user_message);
   }
+
+  /**
+   * Tests cached pages are not shown to users when in maintenance mode.
+   */
+  function testCachedPagesNotServed() {
+    // Log in as admin user and turn on page caching.
+    $this->drupalLogin($this->admin_user);
+    $edit = array(
+      'page_cache_maximum_age' => 300,
+      'cache' => 1,
+    );
+    $this->drupalPostForm('admin/config/development/performance', $edit, t('Save configuration'));
+
+    // Create a node that we can check for caching.
+    $edit = array(
+      'title' => 'do not show this node',
+    );
+    $this->drupalCreateNode($edit);
+    // Visit a node page as an anonymous user.
+    $this->drupalLogout();
+    $this->drupalGet('node/1');
+
+    // Turn on maintenance mode.
+    $this->drupalLogin($this->admin_user);
+    $edit = array(
+      'maintenance_mode' => 1,
+    );
+    $this->drupalPostForm('admin/config/development/maintenance', $edit, t('Save configuration'));
+
+    // Check that a cached node page is not shown in maintenance mode.
+    $this->drupalLogout();
+    $this->drupalGet('node/1');
+    $this->assertText('Site under maintenance', 'Cached pages not shown in maintenance mode.');
+  }
+
 }
