diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php
index 538ab6d..c1f8344 100644
--- a/core/lib/Drupal/Core/Config/Config.php
+++ b/core/lib/Drupal/Core/Config/Config.php
@@ -274,16 +274,22 @@ public function castValue($value) {
   /**
    * Unsets value in this config object.
    *
-   * @param $key
-   *   Name of the key whose value should be unset.
+   * @param string $key
+   *   (optional) The name of the key whose value should be unset. If omitted,
+   *   the entire config object is emptied.
    */
-  public function clear($key) {
-    $parts = explode('.', $key);
-    if (count($parts) == 1) {
-      unset($this->data[$key]);
+  public function clear($key = NULL) {
+    if (!isset($key)) {
+      $this->data = array();
     }
     else {
-      NestedArray::unsetValue($this->data, $parts);
+      $parts = explode('.', $key);
+      if (count($parts) == 1) {
+        unset($this->data[$key]);
+      }
+      else {
+        NestedArray::unsetValue($this->data, $parts);
+      }
     }
     $this->resetOverriddenData();
     return $this;
diff --git a/core/modules/config/lib/Drupal/config/ConfigStorageController.php b/core/modules/config/lib/Drupal/config/ConfigStorageController.php
index 12d62b4..ee94af0 100644
--- a/core/modules/config/lib/Drupal/config/ConfigStorageController.php
+++ b/core/modules/config/lib/Drupal/config/ConfigStorageController.php
@@ -270,6 +270,10 @@ public function save(StorableInterface $entity) {
     $this->preSave($entity);
     $this->invokeHook('presave', $entity);
 
+    // Clear out any possibly existing keys in an existing configuration object,
+    // so any potentially stale keys are removed.
+    $config->clear();
+
     // Configuration objects do not have a schema. Extract all key names from
     // class properties.
     $class_info = new \ReflectionClass($entity);
