diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
index 4566cb11d5..8c2d5b8c8d 100644
--- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php
+++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php
@@ -89,7 +89,14 @@ public function execute() {
       $direction = $sort['direction'] == 'ASC' ? -1 : 1;
       $field = $sort['field'];
       uasort($result, function ($a, $b) use ($field, $direction) {
-        return ($a[$field] <= $b[$field]) ? $direction : -$direction;
+        $properties = explode('.', $field);
+        foreach ($properties as $property) {
+          if (isset($a[$property]) || isset($b[$property])) {
+            $a = isset($a[$property]) ? $a[$property] : NULL;
+            $b = isset($b[$property]) ? $b[$property] : NULL;
+          }
+        }
+        return ($a <= $b) ? $direction : -$direction;
       });
     }
 
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php
index 8dc101a465..55859c038c 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php
@@ -107,6 +107,27 @@ protected function setUp() {
     $this->entities[] = $entity;
     $entity->enforceIsNew();
     $entity->save();
+
+    $array['level1'] = [];
+    $entity = ConfigQueryTest::create([
+      'label' => $this->randomMachineName(),
+      'id' => '6',
+      'array' => $array,
+    ]);
+    $this->entities[] = $entity;
+    $entity->enforceIsNew();
+    $entity->save();
+
+    $array['level1']['level2'] = 4;
+    $entity = ConfigQueryTest::create([
+      'label' => $this->randomMachineName(),
+      'id' => '7',
+      'number' => 70,
+      'array' => $array,
+    ]);
+    $this->entities[] = $entity;
+    $entity->enforceIsNew();
+    $entity->save();
   }
 
   /**
@@ -116,11 +137,11 @@ public function testConfigEntityQuery() {
     // Run a test without any condition.
     $this->queryResults = $this->factory->get('config_query_test')
       ->execute();
-    $this->assertResults(['1', '2', '3', '4', '5']);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
     // No conditions, OR.
     $this->queryResults = $this->factory->get('config_query_test', 'OR')
       ->execute();
-    $this->assertResults(['1', '2', '3', '4', '5']);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
 
     // Filter by ID with equality.
     $this->queryResults = $this->factory->get('config_query_test')
@@ -162,19 +183,19 @@ public function testConfigEntityQuery() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', '3', '>')
       ->execute();
-    $this->assertResults(['4', '5']);
+    $this->assertResults(['4', '5', '6', '7']);
 
     // Filter by ID with the >= operator.
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', '3', '>=')
       ->execute();
-    $this->assertResults(['3', '4', '5']);
+    $this->assertResults(['3', '4', '5', '6', '7']);
 
     // Filter by ID with the <> operator.
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', '3', '<>')
       ->execute();
-    $this->assertResults(['1', '2', '4', '5']);
+    $this->assertResults(['1', '2', '4', '5', '6', '7']);
 
     // Filter by ID with the < operator.
     $this->queryResults = $this->factory->get('config_query_test')
@@ -219,7 +240,7 @@ public function testConfigEntityQuery() {
       ->condition('number', 10, '>=')
       ->condition('number', 50, '>=')
       ->execute();
-    $this->assertResults(['3', '5']);
+    $this->assertResults(['3', '5', '7']);
 
     // Filter with an OR condition group.
     $this->queryResults = $this->factory->get('config_query_test', 'OR')
@@ -242,7 +263,7 @@ public function testConfigEntityQuery() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', ['1', '2'], 'NOT IN')
       ->execute();
-    $this->assertResults(['3', '4', '5']);
+    $this->assertResults(['3', '4', '5', '6', '7']);
 
     // Filter with an OR condition group on different fields.
     $this->queryResults = $this->factory->get('config_query_test', 'OR')
@@ -321,7 +342,7 @@ public function testConfigEntityQuery() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->exists('id')
       ->execute();
-    $this->assertResults(['1', '2', '3', '4', '5']);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
 
     $this->queryResults = $this->factory->get('config_query_test')
       ->exists('non-existent')
@@ -336,7 +357,7 @@ public function testConfigEntityQuery() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->notExists('non-existent')
       ->execute();
-    $this->assertResults(['1', '2', '3', '4', '5']);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
   }
 
   /**
@@ -429,38 +450,38 @@ public function testSortRange() {
     $this->queryResults = $this->factory->get('config_query_test')
       ->sort('number', 'DESC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['3', '5', '2', '1', '4']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '3', '5', '2', '1', '4', '6']);
 
     $this->queryResults = $this->factory->get('config_query_test')
       ->sort('number', 'ASC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['4', '1', '2', '5', '3']);
+    $this->assertIdentical(array_values($this->queryResults), ['6', '4', '1', '2', '5', '3', '7']);
 
     // Apply some filters and sort.
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', '3', '>')
       ->sort('number', 'DESC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['5', '4']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '5', '4', '6']);
 
     $this->queryResults = $this->factory->get('config_query_test')
       ->condition('id', '3', '>')
       ->sort('number', 'ASC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['4', '5']);
+    $this->assertIdentical(array_values($this->queryResults), ['6', '4', '5', '7']);
 
     // Apply a pager and sort.
     $this->queryResults = $this->factory->get('config_query_test')
       ->sort('number', 'DESC')
       ->range('2', '2')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['2', '1']);
+    $this->assertIdentical(array_values($this->queryResults), ['5', '2']);
 
     $this->queryResults = $this->factory->get('config_query_test')
       ->sort('number', 'ASC')
       ->range('2', '2')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['2', '5']);
+    $this->assertIdentical(array_values($this->queryResults), ['1', '2']);
 
     // Add a range to a query without a start parameter.
     $this->queryResults = $this->factory->get('config_query_test')
@@ -492,28 +513,28 @@ public function testTableSort() {
       ->tableSort($header)
       ->sort('id', 'DESC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['5', '4', '3', '2', '1']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '6', '5', '4', '3', '2', '1']);
 
     // Sorting with 'ASC' upper case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('id', 'ASC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['1', '2', '3', '4', '5']);
+    $this->assertIdentical(array_values($this->queryResults), ['1', '2', '3', '4', '5', '6', '7']);
 
     // Sorting with 'desc' lower case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('id', 'desc')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['5', '4', '3', '2', '1']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '6', '5', '4', '3', '2', '1']);
 
     // Sorting with 'asc' lower case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('id', 'asc')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['1', '2', '3', '4', '5']);
+    $this->assertIdentical(array_values($this->queryResults), ['1', '2', '3', '4', '5', '6', '7']);
 
     // Sort key: number
     // Sorting with 'DeSc' mixed upper and lower case
@@ -521,28 +542,28 @@ public function testTableSort() {
       ->tableSort($header)
       ->sort('number', 'DeSc')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['3', '5', '2', '1', '4']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '3', '5', '2', '1', '4', '6']);
 
     // Sorting with 'AsC' mixed upper and lower case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('number', 'AsC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['4', '1', '2', '5', '3']);
+    $this->assertIdentical(array_values($this->queryResults), ['6', '4', '1', '2', '5', '3', '7']);
 
     // Sorting with 'dEsC' mixed upper and lower case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('number', 'dEsC')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['3', '5', '2', '1', '4']);
+    $this->assertIdentical(array_values($this->queryResults), ['7', '3', '5', '2', '1', '4', '6']);
 
     // Sorting with 'aSc' mixed upper and lower case
     $this->queryResults = $this->factory->get('config_query_test')
       ->tableSort($header)
       ->sort('number', 'aSc')
       ->execute();
-    $this->assertIdentical(array_values($this->queryResults), ['4', '1', '2', '5', '3']);
+    $this->assertIdentical(array_values($this->queryResults), ['6', '4', '1', '2', '5', '3', '7']);
   }
 
   /**
@@ -565,6 +586,15 @@ public function testDotted() {
       ->condition('array.level1.level2', 3)
       ->execute();
     $this->assertResults(['5']);
+    // Test dotted sorting.
+    $this->queryResults = $this->factory->get('config_query_test')
+      ->sort('array.level1.level2')
+      ->execute();
+    $this->assertResults(['6', '1', '3', '2', '4', '5', '7']);
+    $this->queryResults = $this->factory->get('config_query_test')
+      ->sort('array.level1.level2', 'DESC')
+      ->execute();
+    $this->assertResults(['7', '5', '2', '4', '1', '3', '6']);
     // Make sure that values on the wildcard level do not match if there are
     // sub-keys defined. This must not find anything even if entity 2 has a
     // top-level key number with value 41.
@@ -574,23 +604,22 @@ public function testDotted() {
     $this->assertResults([]);
     // Make sure that "IS NULL" and "IS NOT NULL" work correctly with
     // array-valued fields/keys.
-    $all = ['1', '2', '3', '4', '5'];
     $this->queryResults = $this->factory->get('config_query_test')
       ->exists('array.level1.level2')
       ->execute();
-    $this->assertResults($all);
+    $this->assertResults(['1', '2', '3', '4', '5', '7']);
     $this->queryResults = $this->factory->get('config_query_test')
       ->exists('array.level1')
       ->execute();
-    $this->assertResults($all);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
     $this->queryResults = $this->factory->get('config_query_test')
       ->exists('array')
       ->execute();
-    $this->assertResults($all);
+    $this->assertResults(['1', '2', '3', '4', '5', '6', '7']);
     $this->queryResults = $this->factory->get('config_query_test')
       ->notExists('array.level1.level2')
       ->execute();
-    $this->assertResults([]);
+    $this->assertResults(['6']);
     $this->queryResults = $this->factory->get('config_query_test')
       ->notExists('array.level1')
       ->execute();
