diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index 18e0260..a370552 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -230,7 +230,7 @@ public function preSave(EntityStorageControllerInterface $storage_controller) {
       ->condition('uuid', $this->uuid())
       ->execute();
     $matched_entity = reset($matching_entities);
-    if (!empty($matched_entity) && ($matched_entity != $this->id())) {
+    if (!empty($matched_entity) && ($matched_entity != $this->id()) && $matched_entity != $this->getOriginalId()) {
       throw new ConfigDuplicateUUIDException(format_string('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity)));
     }
 
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
index 8a26ec0..234ad2a 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php
@@ -311,6 +311,14 @@ public function save(EntityInterface $entity) {
       $entity->original = $this->load($id);
     }
 
+    // Build an ID if none is set.
+    if (!isset($entity->{$this->idKey})) {
+      $entity->{$this->idKey} = $entity->id();
+    }
+
+    $entity->preSave($this);
+    $this->invokeHook('presave', $entity);
+
     if ($id !== $entity->id()) {
       // Renaming a config object needs to cater for:
       // - Storage controller needs to access the original object.
@@ -319,14 +327,6 @@ public function save(EntityInterface $entity) {
       $config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
     }
 
-    // Build an ID if none is set.
-    if (!isset($entity->{$this->idKey})) {
-      $entity->{$this->idKey} = $entity->id();
-    }
-
-    $entity->preSave($this);
-    $this->invokeHook('presave', $entity);
-
     // Retrieve the desired properties and set them in config.
     foreach ($entity->getExportProperties() as $key => $value) {
       $config->set($key, $value);
