diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php
index 5e2ac1e..d0e839a 100644
--- a/core/lib/Drupal/Core/Config/FileStorage.php
+++ b/core/lib/Drupal/Core/Config/FileStorage.php
@@ -128,6 +128,13 @@ class FileStorage {
    * Implements StorageInterface::encode().
    */
   public static function encode($data) {
+    // Maintain order in the first two dimensions.
+    ksort($data);
+    foreach ($data as &$value) {
+      if (is_array($value)) {
+        ksort($value);
+      }
+    }
     // The level where you switch to inline YAML is set to PHP_INT_MAX to ensure
     // this does not occur.
     return Yaml::dump($data, PHP_INT_MAX);
