diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
index 0ecced0..86bc703 100644
--- a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
@@ -332,6 +332,25 @@ public function testUserHandler() {
       ),
     );
     $this->assertReferenceable($selection_options, $referenceable_tests, 'User handler (does not include anonymous)');
+
+    // Check that the Anonymous user is not included in the results when no
+    // label matching is done, for example when using the 'options_select'
+    // widget.
+    $referenceable_tests = array(
+      array(
+        'arguments' => array(
+          array(NULL),
+        ),
+        'result' => array(
+          'user' => array(
+            $users['admin']->id() => $user_labels['admin'],
+            $users['non_admin']->id() => $user_labels['non_admin'],
+            $users['blocked']->id() => $user_labels['blocked'],
+          ),
+        ),
+      ),
+    );
+    $this->assertReferenceable($selection_options, $referenceable_tests, 'User handler (does not include anonymous)');
   }
 
   /**
diff --git a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
index fb0d714..8dfba39 100644
--- a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
+++ b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
@@ -143,6 +143,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    */
   protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
     $query = parent::buildEntityQuery($match, $match_operator);
+    $handler_settings = $this->configuration['handler_settings'];
+
+    // Filter out the Anonymous user if the selection handler is configured to
+    // exclude it.
+    if (isset($handler_settings['include_anonymous']) && !$handler_settings['include_anonymous']) {
+      $query->condition('uid', 0, '<>');
+    }
 
     // The user entity doesn't have a label column.
     if (isset($match)) {
@@ -150,7 +157,6 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
     }
 
     // Filter by role.
-    $handler_settings = $this->configuration['handler_settings'];
     if (!empty($handler_settings['filter']['role'])) {
       $query->condition('roles', $handler_settings['filter']['role'], 'IN');
     }
