diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php
index d225150..3add89d 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php
@@ -46,5 +46,13 @@ function testUserAutocomplete() {
 
     // Using first letter of the user's name, make sure the user's full name is in the results.
     $this->assertRaw($this->unprivileged_user->name, 'User name found in autocompletion results.');
+
+    // Test that anonymous username is in the result.
+    $anonymous_name = $this->randomName();
+    config('user.settings')->set('anonymous', $anonymous_name)->save();
+    $this->drupalGet('user/autocomplete/1', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4))));
+    $this->assertRaw($anonymous_name, 'The anonymous name found in autocompletion results.');
+    $this->drupalGet('user/autocomplete', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4))));
+    $this->assertNoRaw($anonymous_name, 'The anonymous name not found in autocompletion results without enabling anonymous username.');
   }
 }
diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc
index a805258..67d3ab7 100644
--- a/core/modules/user/user.pages.inc
+++ b/core/modules/user/user.pages.inc
@@ -12,11 +12,24 @@
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 
 /**
- * Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.
+ * Menu callback for user autocompletion.
+ *
+ * @param bool $autocomplete_anonymous
+ *   Allows to autocomplete the anonymous user name.
+ *
+ * @return \Symfony\Component\HttpFoundation\JsonResponse
+ *   A json response containing the autocomplete suggestions for existing users.
  */
-function user_autocomplete() {
+function user_autocomplete($autocomplete_anonymous = FALSE) {
   $matches = array();
   if ($string = drupal_container()->get('request')->query->get('q')) {
+    if ($autocomplete_anonymous) {
+      $anonymous_name = config('user.settings')->get('anonymous');
+      // Allow autocompletion for the anonymous user.
+      if (stripos($anonymous_name, $string) !== FALSE) {
+        $matches[$anonymous_name] = $anonymous_name;
+      }
+    }
     $result = db_select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
     foreach ($result as $account) {
       $matches[$account->name] = check_plain($account->name);
