diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index e3fd2256c1..d10cf67e6c 100644
--- a/core/includes/errors.inc
+++ b/core/includes/errors.inc
@@ -180,7 +180,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
       // Should not translate the string to avoid errors producing more errors.
       $response->setContent(html_entity_decode(strip_tags(SafeMarkup::format('%type: @message in %function (line %line of %file).', $error))) . "\n");
       $response->send();
-      exit;
+      exit(1);
     }
   }
 
diff --git a/core/modules/system/tests/src/Kernel/Errors/DrupalLogErrorTest.php b/core/modules/system/tests/src/Kernel/Errors/DrupalLogErrorTest.php
new file mode 100644
index 0000000000..47a33be1d2
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Errors/DrupalLogErrorTest.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Error;
+
+use Drupal\KernelTests\KernelTestBase;
+use Symfony\Component\Process\Process;
+
+/**
+ * Tests logging of errors in core/error.inc.
+ *
+ * @group Error
+ */
+class DrupalLogErrorTest extends KernelTestBase {
+
+  /**
+   * Test that fatal errors return a non-zero exit code.
+   */
+  public function testFatalExitCode() {
+    $process = new Process('php core/modules/system/tests/src/Kernel/Errors/log-exit.php');
+    $process->run();
+    $this->assertFalse($process->isSuccessful());
+  }
+
+}
diff --git a/core/modules/system/tests/src/Kernel/Errors/log-exit.php b/core/modules/system/tests/src/Kernel/Errors/log-exit.php
new file mode 100644
index 0000000000..6c43b2395d
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Errors/log-exit.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Helper to test that _drupal_log_error() sets an error code on exit.
+ *
+ * @see \Drupal\Tests\system\Kernel\Error\DrupalLogErrorTest
+ */
+
+use Drupal\Core\DrupalKernel;
+use Symfony\Component\HttpFoundation\Request;
+
+// Default settings as set by core/scripts/drupal.sh.
+$cmd = 'index.php';
+$_SERVER['HTTP_HOST']       = 'default';
+$_SERVER['PHP_SELF']        = '/core/modules/system/tests/src/Kernel/Errors/log-exit.php';
+$_SERVER['REMOTE_ADDR']     = '127.0.0.1';
+$_SERVER['SERVER_SOFTWARE'] = NULL;
+$_SERVER['REQUEST_METHOD']  = 'GET';
+$_SERVER['QUERY_STRING']    = '';
+$_SERVER['PHP_SELF']        = $_SERVER['REQUEST_URI'] = '/';
+$_SERVER['HTTP_USER_AGENT'] = 'console';
+
+$autoloader = require_once 'autoload.php';
+
+$kernel = new DrupalKernel('prod', $autoloader);
+
+$request = Request::createFromGlobals();
+
+require_once 'core/includes/bootstrap.inc';
+require_once 'core/includes/errors.inc';
+define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
+$error = [
+  '%type' => 'kernel test',
+  '@message' => 'This is a test message',
+  '%function' => 'test_function',
+  '%file' => 'test.module',
+  '%line' => 456,
+  '@backtrace_string' => 'backtrace',
+  'severity_level' => 0,
+  'backtrace' => [],
+];
+_drupal_log_error($error, TRUE);
