diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index ec7e0ed7d88ad949db7b142f6b003e87456ffb5e..16dfd7210bc1811cedd132467136ab6e514325bc 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Utility\Html;
+use Drupal\Core\Installer\InstallerKernel;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Link;
 use Drupal\Core\Url;
@@ -86,8 +87,18 @@ function block_page_top(array &$page_top) {
  *
  * @param $theme_list
  *   An array of theme names.
+ *
+ * @see block_modules_installed()
  */
 function block_themes_installed($theme_list) {
+  // Disable this functionality prior to install profile installation because
+  // block configuration is often optional or provided by the install profile
+  // itself. block_theme_initialize() will be called when the install profile is
+  // installed.
+  if (InstallerKernel::installationAttempted() && \Drupal::config('core.extension')->get('module.' . \Drupal::installProfile()) === NULL) {
+    return;
+  }
+
   foreach ($theme_list as $theme) {
     // Don't initialize themes that are not displayed in the UI.
     if (\Drupal::service('theme_handler')->hasUi($theme)) {
@@ -133,6 +144,24 @@ function block_theme_initialize($theme) {
   }
 }
 
+/**
+ * Implements hook_modules_installed().
+ *
+ * @see block_themes_installed()
+ */
+function block_modules_installed($modules) {
+  // block_themes_installed() does not call block_theme_initialize() during site
+  // installation because block configuration can be optional or provided by the
+  // profile. Now, when the profile is installed, this configuration exists,
+  // call block_theme_initialize() for all installed themes.
+  $profile = \Drupal::installProfile();
+  if (in_array($profile, $modules, TRUE)) {
+    foreach (\Drupal::service('theme_handler')->listInfo() as $theme => $data) {
+      block_theme_initialize($theme);
+    }
+  }
+}
+
 /**
  * Implements hook_rebuild().
  */
diff --git a/core/profiles/testing_themes_blocks/config/install/system.theme.yml b/core/profiles/testing_themes_blocks/config/install/system.theme.yml
new file mode 100644
index 0000000000000000000000000000000000000000..0d1badf630fa1d3ecc44991cc861c616bb48a6c1
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/config/install/system.theme.yml
@@ -0,0 +1,2 @@
+admin: testing_theme_optional_blocks
+default: testing_theme_required_blocks
diff --git a/core/profiles/testing_themes_blocks/testing_themes_blocks.info.yml b/core/profiles/testing_themes_blocks/testing_themes_blocks.info.yml
new file mode 100644
index 0000000000000000000000000000000000000000..c5ffe2148e62d7377267b8bb95f6c7832fbf53f7
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/testing_themes_blocks.info.yml
@@ -0,0 +1,11 @@
+name: Testing themes blocks
+type: profile
+description: 'Minimal profile for testing block installation of themes.'
+version: VERSION
+hidden: true
+themes:
+  - testing_theme_optional_blocks
+  - testing_theme_required_blocks
+  - testing_theme_without_blocks
+install:
+  - block
diff --git a/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/config/optional/block.block.testing_theme_optional_blocks_page_title.yml b/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/config/optional/block.block.testing_theme_optional_blocks_page_title.yml
new file mode 100644
index 0000000000000000000000000000000000000000..9377cb4721d1c8a8907b7bc0f977044367de6033
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/config/optional/block.block.testing_theme_optional_blocks_page_title.yml
@@ -0,0 +1,17 @@
+langcode: en
+status: true
+dependencies:
+  theme:
+    - testing_theme_optional_blocks
+id: testing_theme_optional_blocks_page_title
+theme: testing_theme_optional_blocks
+region: header
+weight: -30
+provider: null
+plugin: page_title_block
+settings:
+  id: page_title_block
+  label: 'Page title'
+  provider: core
+  label_display: '0'
+visibility: {  }
diff --git a/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/testing_theme_optional_blocks.info.yml b/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/testing_theme_optional_blocks.info.yml
new file mode 100644
index 0000000000000000000000000000000000000000..8d24aae82903da296fece159e94d3f32763c84b2
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/themes/testing_theme_optional_blocks/testing_theme_optional_blocks.info.yml
@@ -0,0 +1,15 @@
+name: Testing theme with optional blocks
+type: theme
+base theme: false
+package: Testing
+version: VERSION
+regions:
+  header: 'Header'
+  pre_content: 'Pre-content'
+  breadcrumb: Breadcrumb
+  highlighted: Highlighted
+  help: Help
+  content: Content
+  page_top: 'Page top'
+  page_bottom: 'Page bottom'
+  sidebar_first: 'First sidebar'
diff --git a/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/config/install/block.block.testing_theme_required_blocks_account_menu.yml b/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/config/install/block.block.testing_theme_required_blocks_account_menu.yml
new file mode 100644
index 0000000000000000000000000000000000000000..83aca4cb98b0000e2073382c0c51328a30177d5e
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/config/install/block.block.testing_theme_required_blocks_account_menu.yml
@@ -0,0 +1,20 @@
+langcode: en
+status: true
+dependencies:
+  theme:
+    - testing_theme_required_blocks
+id: testing_theme_required_blocks_account_menu
+theme: testing_theme_required_blocks
+region: secondary_menu
+weight: -4
+provider: null
+plugin: system_menu_block:account
+settings:
+  id: system_menu_block:account
+  label: 'User account menu'
+  provider: system
+  label_display: '0'
+  level: 1
+  depth: 1
+  expand_all_items: false
+visibility: {  }
diff --git a/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/testing_theme_required_blocks.info.yml b/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/testing_theme_required_blocks.info.yml
new file mode 100644
index 0000000000000000000000000000000000000000..baa33b506bf5b658918c20d2a6c56006c36f66db
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/themes/testing_theme_required_blocks/testing_theme_required_blocks.info.yml
@@ -0,0 +1,15 @@
+name: Testing theme with required blocks
+type: theme
+base theme: false
+package: Testing
+version: VERSION
+regions:
+  header: 'Header'
+  pre_content: 'Pre-content'
+  breadcrumb: Breadcrumb
+  highlighted: Highlighted
+  help: Help
+  content: Content
+  page_top: 'Page top'
+  page_bottom: 'Page bottom'
+  sidebar_first: 'First sidebar'
diff --git a/core/profiles/testing_themes_blocks/themes/testing_theme_without_blocks/testing_theme_without_blocks.info.yml b/core/profiles/testing_themes_blocks/themes/testing_theme_without_blocks/testing_theme_without_blocks.info.yml
new file mode 100644
index 0000000000000000000000000000000000000000..6d47cb66fa6d66627f4cff5d409f256bd3fef0c9
--- /dev/null
+++ b/core/profiles/testing_themes_blocks/themes/testing_theme_without_blocks/testing_theme_without_blocks.info.yml
@@ -0,0 +1,15 @@
+name: Testing theme without blocks
+type: theme
+base theme: false
+package: Testing
+version: VERSION
+regions:
+  header: 'Header'
+  pre_content: 'Pre-content'
+  breadcrumb: Breadcrumb
+  highlighted: Highlighted
+  help: Help
+  content: Content
+  page_top: 'Page top'
+  page_bottom: 'Page bottom'
+  sidebar_first: 'First sidebar'
diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerThemesBlocksProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerThemesBlocksProfileTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..2f99801d0e5f912b13fdc64f2ada940ae8d5edbd
--- /dev/null
+++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerThemesBlocksProfileTest.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\FunctionalTests\Installer;
+
+use Drupal\block\Entity\Block;
+
+/**
+ * Verifies that the installer does not generate theme blocks.
+ *
+ * @group Installer
+ */
+class InstallerThemesBlocksProfileTest extends InstallerTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $defaultTheme = 'testing_theme_required_blocks';
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $profile = 'testing_themes_blocks';
+
+  /**
+   * Verify that there is no automatic block generation.
+   */
+  public function testInstaller() {
+
+    // Account menu is a block that testing_theme_required_blocks provides,
+    // but not testing_theme_optional_blocks. There shouldn't be a account menu
+    // block for testing_theme_optional_blocks after the installation.
+    $this->assertEmpty(Block::load('testing_theme_optional_blocks_account_menu'));
+    $this->assertNotEmpty(Block::load('testing_theme_optional_blocks_page_title'));
+
+    // Ensure that for themes without blocks, some default blocks will be
+    // created.
+    $this->assertNotEmpty(Block::load('testing_theme_without_blocks_account_menu'));
+  }
+
+}