diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 5c99840..7dad3c1 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -1050,15 +1050,17 @@ protected function initializeSettings(Request $request) {
       }
       if (!empty($loader)) {
         $this->classLoader->unregister();
-        $loader->register();
-        $old_loader = $this->classLoader;
-        $this->classLoader = $loader;
         // The optimized classloader might be persistent and store cache misses.
         // For example, once a cache miss is stored in APCu clearing it on a
         // specific web-head will not clear any other web-heads. Therefore
         // fallback to the composer class loader that only statically caches
         // misses.
-        $old_loader->register();
+        $old_loader = $this->classLoader;
+        $this->classLoader = $loader;
+        // Our class loaders are preprended to ensure they come first like the
+        // class loader they are replacing.
+        $old_loader->register(TRUE);
+        $loader->register(TRUE);
       }
     }
   }
diff --git a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
index 36caa00..81f1818 100644
--- a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
+++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
@@ -5,6 +5,7 @@
   use Drupal\Core\DrupalKernel;
   use Drupal\Tests\UnitTestCase;
   use org\bovigo\vfs\vfsStream;
+  use Symfony\Component\ClassLoader\ApcClassLoader;
   use Symfony\Component\HttpFoundation\Request;
 
   /**
@@ -48,6 +49,63 @@ public function testTrustedHosts($host, $server_name, $message, $expected = FALS
     }
 
     /**
+     * Tests the reregistration of autoloaders if APCu available.
+     *
+     * This test runs in a separate process since it registers class loaders and
+     * results in statics being set.
+     *
+     * @runInSeparateProcess
+     * @preserveGlobalState disabled
+     * @requires function apcu_fetch
+     * @covers ::initializeSettings
+     */
+    public function testInitializeSettings() {
+      $request = new Request();
+      $classloader = new fakeAutoloader();
+
+      // Create a kernel suitable for testing.
+      $kernel = $this->getMockBuilder(DrupalKernel::class)
+        ->disableOriginalConstructor()
+        ->setMethods(['do_not_mock_any_methods'])
+        ->getMock();
+      $classloader_property = new \ReflectionProperty($kernel, 'classLoader');
+      $classloader_property->setAccessible(TRUE);
+      $classloader_property->setValue($kernel, $classloader);
+      $method = new \ReflectionMethod($kernel, 'initializeSettings');
+      $method->setAccessible(TRUE);
+
+      // Prepend another autoloader to simulate Drush's autoloader.
+      $fake_drush_autoloader = function () {
+        return NULL;
+      };
+      spl_autoload_register($fake_drush_autoloader, TRUE, TRUE);
+
+      // Before calling DrupalKernel::initializeSettings() the first autoloader
+      // is the fake Drush autoloader.
+      $this->assertSame($fake_drush_autoloader, spl_autoload_functions()[0]);
+
+      // Call DrupalKernel::initializeSettings() to simulate part of a Drupal
+      // bootstrap. During the include of autoload.php Composer would prepend
+      // Drupal's autoloader and then this method should not result in Drush's
+      // autoloader becoming the first autoloader even if it swaps out
+      // Composer's autoloader for an optimised one.
+      $method->invoke($kernel, $request);
+
+      $autoloaders = spl_autoload_functions();
+      // The first autoloader should be the APCu based autoloader.
+      $this->assertInstanceOf(ApcClassLoader::class, $autoloaders[0][0]);
+      // The second autoloader should be the original autoloader the kernel was
+      // constructed with.
+      $this->assertSame($classloader, $autoloaders[1][0]);
+      // The third autoloader should be Drush's autoloader.
+      $this->assertSame($fake_drush_autoloader, $autoloaders[2]);
+
+      // Reset the request factory because it is statically stored on the
+      // request.
+      Request::setFactory(NULL);
+    }
+
+    /**
      * Provides test data for testTrustedHosts().
      */
     public function providerTestTrustedHosts() {
@@ -136,6 +194,49 @@ public function testFindSitePath() {
 
   }
 
+  /**
+   * A fake autoloader for testing
+   */
+  class fakeAutoloader {
+
+    /**
+     * Registers this instance as an autoloader.
+     *
+     * @param bool $prepend
+     *   Whether to prepend the autoloader or not
+     */
+    public function register($prepend = FALSE) {
+      spl_autoload_register(array($this, 'loadClass'), TRUE, $prepend);
+    }
+
+    /**
+     * Unregisters this instance as an autoloader.
+     */
+    public function unregister() {
+      spl_autoload_unregister(array($this, 'loadClass'));
+    }
+
+    /**
+     * Loads the given class or interface.
+     *
+     * @return null
+     *   This class never loads.
+     */
+    public function loadClass() {
+      return NULL;
+    }
+
+    /**
+     * Finds a file by class name while caching lookups to APC.
+     *
+     * @return null
+     *   This class never finds.
+     */
+    public function findFile() {
+      return NULL;
+    }
+
+  }
 }
 
 
