diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php
index c61e50166603b311169db504a4bb7a1e06bbc4cd..64dbf36eb51d3f5d26bf69a375aa4a49b4dfcc86 100644
--- a/core/modules/dblog/src/Controller/DbLogController.php
+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -17,6 +17,7 @@
 use Drupal\user\Entity\User;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Drupal\Core\Link;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
 /**
  * Returns responses for dblog routes.
@@ -242,64 +243,71 @@ public function overview() {
    * @return array
    *   If the ID is located in the Database Logging table, a build array in the
    *   format expected by \Drupal\Core\Render\RendererInterface::render().
+   *
+   * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
+   *   If no event found for the given ID.
    */
   public function eventDetails($event_id) {
-    $build = [];
-    if ($dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject()) {
-      $severity = RfcLogLevel::getLevels();
-      $message = $this->formatMessage($dblog);
-      $username = [
-        '#theme' => 'username',
-        '#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser(),
-      ];
-      $rows = [
-        [
-          ['data' => $this->t('Type'), 'header' => TRUE],
-          $this->t($dblog->type),
-        ],
-        [
-          ['data' => $this->t('Date'), 'header' => TRUE],
-          $this->dateFormatter->format($dblog->timestamp, 'long'),
-        ],
-        [
-          ['data' => $this->t('User'), 'header' => TRUE],
-          ['data' => $username],
-        ],
-        [
-          ['data' => $this->t('Location'), 'header' => TRUE],
-          $this->createLink($dblog->location),
-        ],
-        [
-          ['data' => $this->t('Referrer'), 'header' => TRUE],
-          $this->createLink($dblog->referer),
-        ],
-        [
-          ['data' => $this->t('Message'), 'header' => TRUE],
-          $message,
-        ],
-        [
-          ['data' => $this->t('Severity'), 'header' => TRUE],
-          $severity[$dblog->severity],
-        ],
-        [
-          ['data' => $this->t('Hostname'), 'header' => TRUE],
-          $dblog->hostname,
-        ],
-        [
-          ['data' => $this->t('Operations'), 'header' => TRUE],
-          ['data' => ['#markup' => $dblog->link]],
-        ],
-      ];
-      $build['dblog_table'] = [
-        '#type' => 'table',
-        '#rows' => $rows,
-        '#attributes' => ['class' => ['dblog-event']],
-        '#attached' => [
-          'library' => ['dblog/drupal.dblog'],
-        ],
-      ];
+    $dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject();
+
+    if (empty($dblog)) {
+      throw new NotFoundHttpException();
     }
 
+    $build = [];
+    $severity = RfcLogLevel::getLevels();
+    $message = $this->formatMessage($dblog);
+    $username = [
+      '#theme' => 'username',
+      '#account' => $dblog->uid ? $this->userStorage->load($dblog->uid) : User::getAnonymousUser(),
+    ];
+    $rows = [
+      [
+        ['data' => $this->t('Type'), 'header' => TRUE],
+        $this->t($dblog->type),
+      ],
+      [
+        ['data' => $this->t('Date'), 'header' => TRUE],
+        $this->dateFormatter->format($dblog->timestamp, 'long'),
+      ],
+      [
+        ['data' => $this->t('User'), 'header' => TRUE],
+        ['data' => $username],
+      ],
+      [
+        ['data' => $this->t('Location'), 'header' => TRUE],
+        $this->createLink($dblog->location),
+      ],
+      [
+        ['data' => $this->t('Referrer'), 'header' => TRUE],
+        $this->createLink($dblog->referer),
+      ],
+      [
+        ['data' => $this->t('Message'), 'header' => TRUE],
+        $message,
+      ],
+      [
+        ['data' => $this->t('Severity'), 'header' => TRUE],
+        $severity[$dblog->severity],
+      ],
+      [
+        ['data' => $this->t('Hostname'), 'header' => TRUE],
+        $dblog->hostname,
+      ],
+      [
+        ['data' => $this->t('Operations'), 'header' => TRUE],
+        ['data' => ['#markup' => $dblog->link]],
+      ],
+    ];
+    $build['dblog_table'] = [
+      '#type' => 'table',
+      '#rows' => $rows,
+      '#attributes' => ['class' => ['dblog-event']],
+      '#attached' => [
+        'library' => ['dblog/drupal.dblog'],
+      ],
+    ];
+
     return $build;
   }
 
diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php
index 9f7475b82dbcec3b3d6b1bee7bd39785657fc7df..79298d83bc69c66dbedbf6d90d5fabdcfcdf8b03 100644
--- a/core/modules/dblog/tests/src/Functional/DbLogTest.php
+++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php
@@ -135,6 +135,19 @@ public function testLogEventPage() {
     $this->assertText('Notice', 'The severity was properly displayed on the detail page.');
   }
 
+  /**
+   * Test not-existing log event page.
+   */
+  public function testLogEventNotFoundPage() {
+    // Login the admin user.
+    $this->drupalLogin($this->adminUser);
+
+    // Try to read details of not existing event.
+    $this->drupalGet('admin/reports/dblog/event/999999');
+    // Verify 404 response.
+    $this->assertResponse(404);
+  }
+
   /**
    * Test individual log event page with missing log attributes.
    *