diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php
index ae12c91..6fd2afa 100644
--- a/core/lib/Drupal/Core/Config/ConfigInstaller.php
+++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php
@@ -189,24 +189,35 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende
     });
 
     $all_config = array_merge($existing_config, $list);
+    $all_config = array_combine($all_config, $all_config);
     $config_to_create = $storage->readMultiple($list);
     // Check to see if the corresponding override storage has any overrides or
     // new configuration that can be installed.
     if ($profile_storage) {
       $config_to_create = $profile_storage->readMultiple($list) + $config_to_create;
     }
+    // Sort $config_to_create in the order of the least dependent first.
+    $dependency_manager = new ConfigDependencyManager();
+    $dependency_manager->setData($config_to_create);
+    $config_to_create = array_merge(array_flip($dependency_manager->sortAll()), $config_to_create);
+
     foreach ($config_to_create as $config_name => $data) {
-      // Exclude configuration where its dependencies cannot be met.
-      if (!$this->validateDependencies($config_name, $data, $enabled_extensions, $all_config)) {
-        unset($config_to_create[$config_name]);
-      }
-      // Exclude configuration that does not have a matching dependency.
-      elseif (!empty($dependency)) {
+      // Remove configuration where its dependencies cannot be met.
+      $remove = !$this->validateDependencies($config_name, $data, $enabled_extensions, $all_config);
+      // If $dependency is defined, remove configuration that does not have a
+      // matching dependency.
+      if (!$remove && !empty($dependency)) {
         // Create a light weight dependency object to check dependencies.
         $config_entity = new ConfigEntityDependency($config_name, $data);
-        if (!$config_entity->hasDependency(key($dependency), reset($dependency))) {
-          unset($config_to_create[$config_name]);
-        }
+        $remove = !$config_entity->hasDependency(key($dependency), reset($dependency));
+      }
+
+      if ($remove) {
+        // Remove from the list of configuration to create.
+        unset($config_to_create[$config_name]);
+        // Remove from the list of all configuration. This ensures that any
+        // configuration that depends on this configuration is also removed.
+        unset($all_config[$config_name]);
       }
     }
     if (!empty($config_to_create)) {
diff --git a/core/modules/config/src/Tests/ConfigOtherModuleTest.php b/core/modules/config/src/Tests/ConfigOtherModuleTest.php
index 085ea31..dfc1d1f 100644
--- a/core/modules/config/src/Tests/ConfigOtherModuleTest.php
+++ b/core/modules/config/src/Tests/ConfigOtherModuleTest.php
@@ -64,9 +64,14 @@ public function testInstallOtherModuleFirst() {
 
     // Ensure that optional configuration with unmet dependencies is only
     // installed once all the dependencies are met.
-    $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is not created.');
+    $this->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are not met is not created.');
+    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are not met is not created.');
     $this->installModule('config_install_dependency_test');
-    $this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is now created.');
+    $this->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_unmet whose dependencies are met is now created.');
+    // Although the following configuration entity's are now met it is not
+    // installed because it does not have a direct dependency on the
+    // config_install_dependency_test module.
+    $this->assertNull(entity_load('config_test', 'other_module_test_optional_entity_unmet', TRUE), 'The optional configuration config_test.dynamic.other_module_test_optional_entity_unmet whose dependencies are met is not created.');
   }
 
   /**
diff --git a/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_optional_entity_unmet.yml b/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_optional_entity_unmet.yml
new file mode 100644
index 0000000..2c5c485
--- /dev/null
+++ b/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_optional_entity_unmet.yml
@@ -0,0 +1,11 @@
+id: other_module_test_optional_entity_unmet
+label: 'Other module test to test optional config installation'
+weight: 0
+style: ''
+status: true
+langcode: en
+protected_property: Default
+dependencies:
+  enforced:
+    config:
+      - config_test.dynamic.other_module_test_unmet
