diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index e4f9f264ef..6f2b22f067 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/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php b/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php
new file mode 100644
index 0000000000..b702bcee3a
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Drupal\Tests\Core\Error;
+
+use Drupal\Tests\UnitTestCase;
+use Symfony\Component\Process\Process;
+
+/**
+ * Tests logging of errors in core/error.inc.
+ *
+ * @group Error
+ */
+class DrupalLogErrorTest extends UnitTestCase {
+
+  /**
+   * Test that fatal errors return a non-zero exit code.
+   */
+  public function testFatalExitCode() {
+    $path = __DIR__ . 'fixtures/log-exit.sh';
+    $process = new Process("php $path");
+    $process->run();
+    $this->assertFalse($process->isSuccessful());
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Error/fixtures/log-exit.sh b/core/tests/Drupal/Tests/Core/Error/fixtures/log-exit.sh
new file mode 100644
index 0000000000..d405994b3f
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Error/fixtures/log-exit.sh
@@ -0,0 +1,48 @@
+<?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;
+
+// Block this script from running under a web request.
+if (PHP_SAPI !== 'cli') {
+  return;
+}
+
+// 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);
