diff --git a/core/lib/Drupal/Core/TempStore/PrivateTempStore.php b/core/lib/Drupal/Core/TempStore/PrivateTempStore.php
index 651227c371..3f3bbbb7ff 100644
--- a/core/lib/Drupal/Core/TempStore/PrivateTempStore.php
+++ b/core/lib/Drupal/Core/TempStore/PrivateTempStore.php
@@ -117,6 +117,13 @@ public function get($key) {
    *   Thrown when a lock for the backend storage could not be acquired.
    */
   public function set($key, $value) {
+    // Ensure that an anonymous user has a session created for them, as
+    // otherwise subsequent page loads will not be able to retrieve their
+    // tempstore data.
+    if ($this->currentUser->isAnonymous()) {
+      $this->requestStack->getCurrentRequest()->getSession()->set('forced', TRUE);
+    }
+
     $key = $this->createkey($key);
     if (!$this->lockBackend->acquire($key)) {
       $this->lockBackend->wait($key);
diff --git a/core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php b/core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php
new file mode 100644
index 0000000000..03e567a113
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/TempStore/AnonymousPrivateTempStoreTest.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Drupal\KernelTests\Core\TempStore;
+
+use Drupal\Core\Database\Database;
+use Drupal\Core\KeyValueStore\KeyValueExpirableFactory;
+use Drupal\Core\Lock\DatabaseLockBackend;
+use Drupal\Core\Session\AnonymousUserSession;
+use Drupal\Core\TempStore\PrivateTempStoreFactory;
+use Drupal\KernelTests\KernelTestBase;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Session\Session;
+
+/**
+ * Tests the PrivateTempStore for anonymous users.
+ *
+ * @group TempStore
+ */
+class AnonymousPrivateTempStoreTest extends KernelTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['system'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    // Install system tables to test the key/value storage without installing a
+    // full Drupal environment.
+    $this->installSchema('system', ['key_value_expire']);
+
+    $session = $this->container->get('session');
+    $request = Request::create('/');
+    $request->setSession($session);
+
+    $stack = $this->container->get('request_stack');
+    $stack->pop();
+    $stack->push($request);
+
+  }
+
+  /**
+   * Tests anonymous can get/set to his PrivateTempStore.
+   */
+  public function testAnonymousCanUsePrivateTempStore() {
+    $temp_store = $this->container->get('tempstore.private')->get('anonymous_private_temp_store');
+    $temp_store->set('foo', 'bar');
+    $metadata1 = $temp_store->getMetadata('foo');
+
+    $this->assertEquals('bar', $temp_store->get('foo'));
+    $this->assertNotEmpty($metadata1->owner);
+
+    $temp_store->set('foo', 'bar2');
+    $metadata2 = $temp_store->getMetadata('foo');
+    $this->assertEquals('bar2', $temp_store->get('foo'));
+    $this->assertNotEmpty($metadata2->owner);
+    $this->assertEquals($metadata2->owner, $metadata1->owner);
+  }
+
+}
